FOSSology  4.7.0-rc1
Open Source License Compliance by Open Source Software
schema-export.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
20 /* Note: php 5 getopt() ignores options not specified in the function call, so add
21  * dummy options in order to catch invalid options.
22  */
23 
24 if (!empty($MODDIR)) {
25  $dir = $MODDIR;
26 } else {
27  /* Fallback: derive base dir from cwd (for environments where fo_wrapper did not bootstrap) */
28  $dir = getcwd();
29  if ($dir === false) {
30  print "ERROR: Unable to determine working directory and \$MODDIR is not set.\n";
31  exit(1);
32  }
33  $dir = dirname($dir);
34 }
35 
36 require_once("$dir/lib/php/libschema.php");
37 
38 $AllPossibleOpts = "abc:d:ef:ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
39 
40 /* defaults */
41 $Verbose = false;
42 $DatabaseName = "fossology";
43 $UpdateLiceneseRef = false;
44 $showUsage = false;
45 
46 /* default location of core-schema.dat. This file is checked into svn */
47 $SchemaFilePath = "$dir/www/ui/core-schema.dat";
48 
49 /* command-line options */
50 $Options = getopt($AllPossibleOpts);
51 foreach ($Options as $Option => $OptVal) {
52  switch ($Option) {
53  case 'c': /* used by fo_wrapper */
54  break;
55  case 'd': /* optional database name */
56  $DatabaseName = $OptVal;
57  break;
58  case 'f': /* schema file */
59  $SchemaFilePath = $OptVal;
60  break;
61  case 'h': /* help */
62  $showUsage = true;
63  break;
64  default:
65  echo "Invalid Option \"$Option\".\n";
66  $showUsage = true;
67  }
68 }
69 
70 if ($showUsage) {
71  global $argv;
72 
73  $usage = "Usage: " . basename($argv[0]) . " [options]
74  Update FOSSology database. Options are:
75  -d {database name} default is 'fossology'
76  -f {output file}
77  -h this help usage";
78  print "$usage\n";
79 } else {
80  if (file_exists($SchemaFilePath) && !@unlink($SchemaFilePath)) {
81  $FailMsg = "Existing schema data file ($SchemaFilePath) could not be removed.";
82  } else {
83  $FailMsg = ExportSchema($SchemaFilePath);
84  }
85 
86  if ($FailMsg !== false) {
87  print "ERROR: $FailMsg \n";
88  exit(1);
89  }
90 }
ExportSchema($filename=NULL)
Export the schema of the connected database to a file in the format readable by GetSchema().
Definition: libschema.php:1157