FOSSology  4.4.0
Open Source License Compliance by Open Source Software
create_test_database.php
1 #!/usr/bin/php
2 <?php
3 /*
4  SPDX-FileCopyrightText: © 2013-2014 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 // If set to TRUE, print additional DEBUG information. Note that
10 // printing this information will prevent the script from working
11 // from within the FOSSology makefiles
12 $debug = FALSE;
13 
14 $start_time = get_time();
15 
16 /*
17  create_test_database.php
18 
19  Create a minimal FOSSology test database and associated configuration,
20  if one does not already exist.
21 
22  This script is intended to provide a minimal PRE-INSTALLATION test
23  environment in which FOSSology Unit, Functional, and other tests can
24  be executed. It allows tests to be run without having the FOSSology
25  system installed on a target test system.
26 
27 
28  Here is what this script does:
29 
30  0) Check whether an environment variable FOSSOLOGY_TESTCONFIG is set
31  If so, this environment variable should point to the fossology
32  testing system configuration directory, which will be something like:
33 
34  /tmp/fossologytest_20120611_172315/
35 
36  If FOSSOLOGY_TESTCONFIG is set, then simply exit.
37  We do not validate the testing environment further, but any
38  subsequent tests should be able to use this test database and
39  system configuration.
40 
41  1) Make sure we can connect to postgres as the 'fossologytest' user.
42 
43  For this to work, the password must be specified in one of:
44 
45  * the PGPASSWORD environment variable
46  * the pgpass file specified by the PGPASSFILE environment variable
47  * the current user's ~/.pgpass file
48 
49  If we cannot connect as user 'fossologytest' then a few things
50  should be checked:
51 
52  a) Is PostgreSQL installed and running?
53  b) Does a 'fossologytest' Postgres user exist?
54  c) is a known password configured for user 'fossologytest'?
55 
56  2) Connect as the fossologytest user and create a new empty database
57 
58  The database should have a unique, easily-identifiable name that we
59  can use in subsequent FOSSology unit, function, or other tests.
60 
61  It will be called: 'fossologytest_YYYYMMDD_hhmmss
62 
63  where YYYYMMDD_hhmmss is a timestamp indicating when the database
64  was created.
65 
66  3) Load the core-schema.dat database schema into the new database
67 
68  This will be the core schema from the current working copy of the
69  FOSSology code from which this script is being executed.
70 
71  4) Create a temporary fossology system configuration directory for testing
72 
73  This is created in the system's temporary directory (e.g. /tmp).
74  It is named after the current testing database timestamp. Example:
75 
76  /tmp/fossologytest_20120611_172315/
77 
78  5) Create a Db.conf file in the testing system config directory
79 
80  This contains the database connection parameters that were just set up
81  and which should be used in subsequent tests. Example:
82 
83  /tmp/fossologytest_20120611_172315/Db.conf
84 
85  6) Create a mods-enabled directory in the temporary fossology system
86  configuration directory, and populate it with symlinks to the
87  working copy of fossology. Example:
88 
89  /tmp/fossologytest_20120611_172315/mods-enabled/adj2nest
90  /tmp/fossologytest_20120611_172315/mods-enabled/buckets
91  ...
92  /tmp/fossologytest_20120611_172315/mods-enabled/www
93 
94  7) Create an empty repository directory in the temporary fossology system
95  configuration directory for use in testing. Example:
96 
97  /tmp/fossologytest_20120611_172315/repository/
98 
99  8) Generate a simple fossology.conf file in the system config directory
100  with appropriate defaults for testing with the temporary fossology
101  test environment. Example:
102 
103  /tmp/fossologytest_20120611_172315/fossology.conf
104 
105 */
106 
107 
108 $test_username = 'fossologytest';
109 $test_environment_variable = 'FOSSOLOGY_TESTCONFIG';
110 
111 /* very first step - check for the FOSSOLOGY_TESTCONFIG environment variable.
112  If this exists, then our job here is done.
113  We simply echo the value to stdout and exit */
114 $fossology_testconfig = getenv($test_environment_variable);
115 
116 if ($fossology_testconfig && strlen($fossology_testconfig) > 1) {
117 
118  // just echo the value of the environment variable, and exit
119  echo "$fossology_testconfig\n";
120  exit(0);
121 
122 }
123 else {
124  debug("Did not find a valid $test_environment_variable environment variable");
125 }
126 
127 
128 
129 // check for a PGPASSWORD or PGPASSFILE environment variable
130 // PGPASSWORD specifies the actual password to use
131 // PGPASSFILE specifies the location of the 'pgpass' file
132 // Otherwise the .pgpass file in the current user's $HOME directory is
133 // where passwords are normally stored.
134 $pgpass_file = getenv('HOME') . '/.pgpass';
135 
136 $pg_password_environment = getenv('PGPASSWORD');
137 $pg_passfile_environment = getenv('PGPASSFILE');
138 
139 if ( $pg_password_environment ) {
140  // A PGPASSWORD environment variable overrides any other
141  // password authentication mechanism
142  debug("Found a PGPASSWORD environment variable of '$pg_password_environment' overriding any PGPASSFILE or ~/.pgpass authentication");
143 }
144 else {
145  if ( $pg_passfile_environment ) {
146  // A PGPASSFILE environment variable specifies the location
147  // of a pgpass file
148  debug("Found a PGPASSFILE environment variable of '$pg_passfile_environment' overriding any ~/.pgpass file");
149  $pgpass_file = $pg_passfile_environment;
150  }
151  if (is_file($pgpass_file)) {
152  $pgpass_perms = substr( sprintf("%o", fileperms($pgpass_file)), -4);
153  if ($pgpass_perms == '0600') {
154  debug("Permissions for $pgpass_file are correct (0600)");
155  $pgpass_contents = file($pgpass_file);
156 
157  // Scan thru the pgpass file for an entry for the test user
158  $testuser_found = FALSE;
159  foreach ($pgpass_contents as $line) {
160  if ( preg_match("/$test_username:[^:]*$/", $line) ) {
161  $testuser_found = TRUE;
162  }
163  }
164 
165  if ( $testuser_found == TRUE ) {
166  debug("Found a '$test_username' user in $pgpass_file");
167  }
168  else {
169  echo "FAIL: Did not find a '$test_username' user in $pgpass_file\n";
170  echo "Before you can run FOSSology tests, you must first create a Postgres user called '$test_username'\n";
171  echo "which has the CREATEDB permission. This can be done using the following SQL command (as the 'psql' Postgres super user):\n";
172  echo "\n CREATE USER $test_username WITH CREATEDB LOGIN PASSWORD '$test_username';\n";
173  echo "\nOnce done, this user needs to be added to a ~/.pgpass file with the following contents:\n";
174  // pgpass file needs an entry like 'localhost:*:*:fossologytest:fossologytest'
175  echo "\nlocalhost:*:*:$test_username:$test_username\n";
176  echo "\nAnd this file must have permissions set to 0600\n";
177  exit(1);
178  }
179  }
180  else {
181  echo "FAIL - Permissions for $pgpass_file are NOT correct, must be 0600\n";
182  exit (1);
183  }
184  }
185  else {
186  echo "FAIL - Pgpass file $pgpass_file does not exist, or is not a regular file\n";
187  exit (1);
188  }
189 }
190 
191 
192 
193 /* Check to see if we can connect to the Postgres server on the
194  local host as the 'fossologytest' user, using the built-in
195  PHP postgres connector
196 */
197 
198 // database 'template1' should exist by default on all Postgres servers
199 $template_db = 'template1';
200 $initial_postgres_params = "dbname=$template_db ";
201 $initial_postgres_params .= "host=localhost ";
202 /* the default Postgres port is 5432 */
203 //$postgres_params .= "port=5432 ";
204 $initial_postgres_params .= "user=$test_username ";
205 
206 // make sure that the new database can actually connect
207 $test_pg_conn = @pg_connect($initial_postgres_params);
208 
209 /* pg_connect returns a database connection handle, or FALSE if it
210  was not able to connect.
211 
212  If we were not able to connect, try to figure out why and
213  provide a helpful message to the tester */
214 if ( $test_pg_conn == FALSE ) {
215 
216  $error_array = error_get_last();
217  $pg_error_message = $error_array['message'];
218  echo "FAIL: Cannot connect to the local Postgres server. ";
219 
220  if ( preg_match('/no password supplied/', $pg_error_message) ) {
221  echo "The '$test_username' user must already exist and be included in a ~/.pgpass file, or the PGPASSWORD environment variable must be set!\n";
222  echo "Before you can run FOSSology tests, you must first create a Postgres user called '$test_username'\n";
223  echo "which has the CREATEDB permission. This can be done using the following SQL command (as the 'psql' Postgres super user):\n";
224  echo "\n CREATE USER $test_username WITH CREATEDB LOGIN PASSWORD '$test_username';\n";
225  echo "\nOnce done, this user needs to be added to a ~/.pgpass file with the following contents:\n";
226  // pgpass file needs an entry like 'localhost:*:*:fossologytest:fossologytest'
227  echo "\nlocalhost:*:*:$test_username:$test_username\n";
228  echo "\nAnd this file must have permissions set to 0600\n";
229  }
230  elseif ( preg_match('/authentication failed/', $pg_error_message) ) {
231  echo "The password for user '$test_username' is not correct!\n";
232  }
233  elseif ( preg_match("/database \"$template_db\" does not exist/", $pg_error_message) ) {
234  echo "The database '$template_db' does not exist!\n";
235  }
236  else {
237  echo "Unknown problem: $pg_error_message\n";
238  }
239 
240  exit(1);
241 }
242 else {
243  debug("Successfully connected to local Postgres server as user '$test_username'");
244 }
245 
246 pg_close($test_pg_conn) or die ("FAIL: We could not close the posgres connection!");
247 
248 
249 /* get the system's temporary directory location. We'll use this as the
250  base for the testing instance of the system config directory */
251 $system_temp_dir = sys_get_temp_dir();
252 
253 /* generate a timestamp directory name for this testing database instance
254  This will be, for example:
255  /tmp/fossologytest_20120611_172315/ */
256 $testing_timestamp = date("Ymd_His");
257 $testing_temp_dir = $system_temp_dir . '/fossologytest_' . $testing_timestamp;
258 
259 mkdir($testing_temp_dir, 0755, TRUE)
260  or die("FAIL! Cannot create test configuration directory at: $testing_temp_dir\n");
261 
262 $elapsed = get_time() - $start_time;
263 debug("Elapsed Time = $elapsed");
264 /* Now create a new, unique dataabase */
265 debug("Creating test database... ");
266 $test_db_name = "fossologytest_$testing_timestamp";
267 
268 // re-connect using the same template1 database as above
269 $test_pg_conn = @pg_connect($initial_postgres_params)
270  or die("FAIL: Could not connect to Postgres server!");
271 
272 $sql_statement="CREATE DATABASE $test_db_name ENCODING='UTF8' TEMPLATE template1";
273 $result = pg_query($test_pg_conn, $sql_statement)
274  or die("FAIL: Could not create test database!\n");
275 
276 // close the connection to the template1 database. Now we can
277 // reconnect to the newly-created test database
278 pg_close($test_pg_conn);
279 
280 debug("Done creating test database");
281 $elapsed = get_time() - $start_time;
282 debug("Elapsed Time = $elapsed");
283 
284 /* Now connect to the newly-created test database */
285 $test_db_params = "dbname=$test_db_name ";
286 $test_db_params .= "host=localhost ";
287 /* the default Postgres port is 5432 */
288 //$postgres_params .= "port=5432 ";
289 $test_db_params .= "user=$test_username ";
290 
291 $test_db_conn = pg_connect($test_db_params)
292  or die ("Could not connect to the new test database '$test_db_name'\n");
293 
294 
295 /* Do some minimal setup of the new database */
296 // Note: from Postgres 9.1 on, can use 'CREATE OR REPLACE LANGUAGE'
297 // instead of dropping and then re-creating
298 
299 // first check to make sure we don't already have the plpgsql language installed
300 $sql_statement = "select lanname from pg_language where lanname = 'plpgsql'";
301 
302 $result = pg_query($test_db_conn, $sql_statement)
303  or die("Could not check the database for plpgsql language\n");
304 
305 $plpgsql_already_installed = FALSE;
306 if ( $row = pg_fetch_row($result) ) {
307  $plpgsql_already_installed = TRUE;
308 }
309 
310 // then create language plpgsql if not already created
311 if ( $plpgsql_already_installed == FALSE ) {
312  $sql_statement = "CREATE LANGUAGE plpgsql";
313  $result = pg_query($test_db_conn, $sql_statement)
314  or die("Could not create plpgsql language in the database\n");
315 }
316 
317 $sql_statement = "select extname from pg_extension where extname = 'uuid-ossp'";
318 
319 $result = pg_query($test_db_conn, $sql_statement)
320  or die("Could not check the database for uuid-ossp extension\n");
321 
322 $uuid_already_installed = FALSE;
323 if ( $row = pg_fetch_row($result) ) {
324  $uuid_already_installed = TRUE;
325 }
326 
327 // then create extension uuid-ossp if not already created
328 if ( $uuid_already_installed == FALSE ) {
329  $sql_statement = 'CREATE EXTENSION "uuid-ossp";';
330  $result = pg_query($test_db_conn, $sql_statement)
331  or die("Could not create uuid-ossp extension in the database\n");
332 }
333 
334 
335 /* now create a valid Db.conf file in the testing temp directory
336  for accessing our fancy pants new test database */
337 $db_conf_fh = fopen("$testing_temp_dir/Db.conf", 'w')
338  or die("FAIL! Cannot write $testing_temp_dir/Db.conf\n");
339 fwrite($db_conf_fh, "dbname = $test_db_name;\n");
340 fwrite($db_conf_fh, "host = localhost;\n");
341 fwrite($db_conf_fh, "user = $test_username;\n");
342 // Note: because the Db.conf file is itself just the parameters
343 // used in the pg_connect() command, we should be able to
344 // safely omit the password, since whatever mechanism was
345 // already in place to authenticate can still be used.
346 //fwrite($db_conf_fh, "password = fossologytest;\n");
347 fclose($db_conf_fh);
348 
349 
350 /* now create a mods-enabled directory to contain symlinks to the
351  agents in the current working copy of fossology */
352 $mods_enabled_dir = "$testing_temp_dir/mods-enabled";
353 
354 mkdir($mods_enabled_dir, 0755, TRUE)
355  or die("FAIL! Cannot create test mods-enabled directory at: $mods_enabled_dir\n");
356 
357 /* here we have to do the work that each of the agents' 'make install'
358  targets would normally do, but since we want the tests to be able
359  to execute before FOSSology is installed, we need to do a minimal
360  amount of work to enable them */
361 
362 /* for each src/ directory above us, create a symlink for it in the
363  temporary testing mods-enabled directory we just created;
364  but always skip the cli and lib directories */
365 
366 $fo_base_dir = realpath(__DIR__ . '/../..');
367 $src_dirs = scandir($fo_base_dir);
368 
369 foreach ($src_dirs as $src_dir) {
370  $full_src_dir = $fo_base_dir . "/" . $src_dir;
371  // skip dotted directories, lib/, cli/, and other irrelevant directories
372  if ( preg_match("/^\./", $src_dir)
373  || $src_dir == 'lib'
374  || $src_dir == 'cli'
375  || $src_dir == 'example_wc_agent'
376  || $src_dir == 'tutorials'
377  || $src_dir == 'srcdocs'
378  || $src_dir == 'testing'
379  || $src_dir == 'demomod'
380  ) {
381  continue;
382  }
383  $splitModuls = array('monk'=>array('monk','monkbulk'),'copyright'=>array('copyright','ecc'));
384  if ( array_key_exists($src_dir,$splitModuls) ) {
385  foreach($splitModuls[$src_dir] as $agent){
386  mkdir("$mods_enabled_dir/$agent");
387  symlink("$full_src_dir/agent", "$mods_enabled_dir/$agent/agent");
388  symlink("$full_src_dir/ui", "$mods_enabled_dir/$agent/ui");
389  symlink("$full_src_dir/$agent.conf", "$mods_enabled_dir/$agent/$agent.conf");
390  symlink("$full_src_dir/VERSION-$agent", "$mods_enabled_dir/$agent/VERSION");
391  }
392  continue;
393  }
394  if (is_dir($full_src_dir)) {
395  symlink($full_src_dir, "$mods_enabled_dir/$src_dir")
396  or die("FAIL - could not create symlink for $src_dir in $mods_enabled_dir\n");
397  }
398 }
399 
400 /*
401 $des_dir = "/srv/fossologyTestRepo/testConf/mods-enabled/";
402 if (is_dir($des_dir)) {
403  symlink($des_dir, "$mods_enabled_dir")
404  or die("FAIL - could not create symlink for $des_dir\n");
405 }
406 else {
407  print "please run make install from source before do the test.\n";
408 }
409 */
410 
411 /* Now let's set up a test repository location, which is just an empty
412  subdirectory within our temporary testing system config directory */
413 $test_repo_dir = "$testing_temp_dir/repository";
414 mkdir($test_repo_dir, 0755, TRUE)
415  or die ("FAIL! Cannot create test repository directory at: $test_repo_dir\n");
416 
417 
418 /* now create a valid fossology.conf file in the testing
419  temp directory */
420 
421 // be lazy and just use a system call to gather user and group name
422 $user_name = rtrim(`id -un`);
423 $group_name = rtrim(`id -gn`);
424 // generate a random port number above 10,000 to use for testing
425 $fo_port_number = mt_rand(10001, 32768);
426 
427 $fo_conf_fh = fopen("$testing_temp_dir/fossology.conf", 'w')
428  or die("FAIL: Could not open $testing_temp_dir/fossology.conf for writing\n");
429 fwrite($fo_conf_fh, "; fossology.conf for testing\n");
430 fwrite($fo_conf_fh, "[FOSSOLOGY]\n");
431 fwrite($fo_conf_fh, "port = $fo_port_number\n");
432 fwrite($fo_conf_fh, "address = localhost\n");
433 fwrite($fo_conf_fh, "depth = 3\n");
434 fwrite($fo_conf_fh, "path = $test_repo_dir\n");
435 fwrite($fo_conf_fh, "[HOSTS]\n");
436 fwrite($fo_conf_fh, "localhost = localhost AGENT_DIR 10\n");
437 fwrite($fo_conf_fh, "[REPOSITORY]\n");
438 fwrite($fo_conf_fh, "localhost = * 00 ff\n");
439 fwrite($fo_conf_fh, "[DIRECTORIES]\n");
440 fwrite($fo_conf_fh, "PROJECTUSER=$user_name\n");
441 fwrite($fo_conf_fh, "PROJECTGROUP=$group_name\n");
442 fwrite($fo_conf_fh, "MODDIR=$fo_base_dir\n");
443 fwrite($fo_conf_fh, "BINDIR=$fo_base_dir/cli\n");
444 fwrite($fo_conf_fh, "SBINDIR=$fo_base_dir/cli\n");
445 fwrite($fo_conf_fh, "LIBEXECDIR=$fo_base_dir/lib\n");
446 fwrite($fo_conf_fh, "LOGDIR=$testing_temp_dir\n");
447 fclose($fo_conf_fh);
448 
449 
450 /* Write a VERSION file */
451 
452 $fo_version_fh = fopen("$testing_temp_dir/VERSION", 'w')
453  or die("FAIL: Could not open $testing_temp_dir/VERSION for writing\n");
454 fwrite($fo_version_fh, "[BUILD]\n");
455 fwrite($fo_version_fh, "VERSION=test\n");
456 fwrite($fo_version_fh, "COMMIT_HASH=0000\n");
457 $build_date = date("Y/m/d H:i");
458 fwrite($fo_version_fh, "BUILD_DATE=$build_date\n");
459 fclose($fo_version_fh);
460 
461 /* now load the fossology core schema into the database */
462 $core_schema_dat_file = $fo_base_dir . "/www/ui/core-schema.dat";
463 
464 // use our existing test database connection to populate the
465 // database with the FOSSology ApplySchema() function
466 
467 // To make absolutely sure we do not interfere with any existing
468 // database connections, save off any pre-existing database connections
469 if (isset($PG_CONN)) {
470  $previous_PG_CONN = $PG_CONN;
471 }
472 
473 // assign the global PG_CONN variable used by ApplySchema
474 $PG_CONN = $test_db_conn;
475 
476 /* We are going to break some testing rules here, by including and
477  using application code within the testing framework:
478 
479  PHP Library: Function we use:
480  ------------ ----------------
481  ../../lib/php/libschema.php ApplySchema() (used to load core-schema.dat)
482  ../../lib/php/common-db.php DBCheckResult()
483  ../../lib/php/common-cache.php ReportCachePurgeAll() (required by ApplySchema)
484 
485 */
486 if(!is_file(__DIR__ . '/../../vendor/autoload.php'))
487 {
488  throw new Exception('you need to run "composer install" before creating a database via ApplySchema');
489 }
490 
491 require_once(__DIR__ . '/../../lib/php/libschema.php');
492 require_once(__DIR__ . '/../../lib/php/common-db.php');
493 require_once(__DIR__ . '/../../lib/php/common-cache.php');
494 require_once(__DIR__ . '/../../../install/fossinit-common.php');
495 
496 global $SysConf;
497 $SysConf = bootstrap($testing_temp_dir);
498 get_pg_conn($testing_temp_dir, $SysConf);
499 
500 // apply the core schema
501 // We need to buffer the output in order to silence the normal
502 // output generated by ApplySchema, or it will interfere with
503 // our makefile interface
504 debug("Applying the FOSSOlogy schema to test database via ApplySchema()");
505 ob_start();
506 $apply_result = ApplySchema($core_schema_dat_file, false, $test_db_name);
507 
508 // then re-assign the previous PG_CONN, if there was one
509 if (isset($previous_PG_CONN)) {
510  $PG_CONN = $previous_PG_CONN;
511 }
512 
513 if (!empty($apply_result)) {
514  die("FAIL: ApplySchema did not succeed. Output was:\n$apply_result\n");
515 }
516 debug("Done Applying the FOSSOlogy schema to test database via ApplySchema()");
517 $elapsed = get_time() - $start_time;
518 debug("Elapsed Time = $elapsed");
519 
520 // insert the 'fossy' user into the test database
521 // this is the FOSSology user 'fossy' (not a Postgres user, or a system user)
522 $random_seed = 'Seed';
523 $options = array('cost' => 10);
524 $hash = password_hash("fossy", PASSWORD_DEFAULT, $options);
525 $user_sql = "INSERT INTO users (user_pk, user_name, user_desc, user_seed, user_pass, user_perm, user_email, email_notify, root_folder_fk) VALUES (1, 'fossy', 'Default Administrator', '$random_seed', '$hash', 10, 'fossy', 'n', 1);";
526 pg_query($test_db_conn, $user_sql)
527  or die("FAIL: could not insert default user into user table\n");
528 
529 // insert top level folder 'Software Repository'
530 $folder_sql = "INSERT INTO folder(folder_pk, folder_name, folder_desc) values(1, 'Software Repository', 'Top Folder');";
531 pg_query($test_db_conn, $folder_sql)
532  or die("FAIL: could not insert top folder\n");
533 $folder_sql = "INSERT INTO foldercontents (parent_fk, foldercontents_mode, child_id) VALUES (1, 0, 0);";
534 pg_query($test_db_conn, $folder_sql)
535  or die("FAIL: could not insert top folder contents\n");
536 $folder_sql = "SELECT setval('folder_folder_pk_seq', (SELECT max(folder_pk) + 1 FROM folder LIMIT 1));";
537 pg_query($test_db_conn, $folder_sql)
538  or die("FAIL: could not change folder sequence\n");
539 
540 $LIBEXECDIR = "$fo_base_dir/lib/";
541 $MODDIR = "$fo_base_dir/";
542 /* for the 2.0 -> 2.1 migration, create the uploadtree_0 table */
543 require_once(__DIR__ . '/../../lib/php/libschema.php');
544 require_once(__DIR__ . "/../../../install/db/dbmigrate_2.0-2.1.php"); // hardcode for now
545 require_once(__DIR__ . "/../../../install/db/dbmigrate_2.1-2.2.php"); // hardcode for now
546 $Verbose = 0;
547 Migrate_20_21($Verbose);
548 Migrate_21_22($Verbose);
549 ob_end_clean();
550 
551 /* now we are done setting up the test database */
552 pg_close($test_db_conn);
553 
554 
555 /* When we finish successfully, print out the testing SYSCONFDIR
556  to stdout as the ONLY output from the script. In this way it
557  can be "imported" into the GNU Make environment */
558 debug("Successful test database creation");
559 $elapsed = get_time() - $start_time;
560 debug("Elapsed Time = $elapsed");
561 echo "$testing_temp_dir\n";
562 
563 // indicate a successful run
564 exit(0);
565 
566 
567 
568 
569 
570 
571 /*********************************************************************
572  *********************************************************************
573  *** ***
574  *** Function definitions ***
575  *** ***
576  *********************************************************************
577  *********************************************************************/
578 
579 // print a debug message, but only when "$debug" is set
580 function debug($message) {
581  global $debug;
582  if ($debug == TRUE) {
583  echo "DEBUG: $message\n";
584  }
585 }
586 
587 // get the time in seconds including decimal microseconds since UNIX epoch
588 function get_time() {
589 
590  list($usec,$sec) = explode(' ', microtime());
591  return ((float)$usec + (float)$sec);
592 
593 }
int debug
Definition: buckets.c:57
get_pg_conn($sysconfdir, &$SysConf, $exitOnDbFail=true)
Migrate_20_21($DryRun)
Migrate to the uploadtree_a table.
Migrate_21_22($Verbose)
Create new groups, group_user_member, perm_upload and perm_folder records to support 2....
fo_conf * conf
The loaded configuration data.
Definition: fo_cli.c:39
ApplySchema($Filename=NULL, $Debug=false, $Catalog='fossology')
Make schema match $Filename. This is a single transaction.
Definition: libschema.php:1101
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: migratetest.php:82
if(!preg_match("/\s$projectGroup\s/", $groups) &&(posix_getgid() !=$gInfo[ 'gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:33
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308