FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
schema-export.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
31 /* Note: php 5 getopt() ignores options not specified in the function call, so add
32  * dummy options in order to catch invalid options.
33  */
34 $AllPossibleOpts = "abc:d:ef:ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
35 
36 /* defaults */
37 $Verbose = false;
38 $DatabaseName = "fossology";
39 $UpdateLiceneseRef = false;
40 $showUsage = false;
41 
42 /* default location of core-schema.dat. This file is checked into svn */
43 $SchemaFilePath = "$MODDIR/www/ui/core-schema.dat";
44 
45 /* command-line options */
46 $Options = getopt($AllPossibleOpts);
47 foreach ($Options as $Option => $OptVal) {
48  switch ($Option) {
49  case 'c': /* used by fo_wrapper */
50  break;
51  case 'd': /* optional database name */
52  $DatabaseName = $OptVal;
53  break;
54  case 'f': /* schema file */
55  $SchemaFilePath = $OptVal;
56  break;
57  case 'h': /* help */
58  $showUsage = true;
59  break;
60  default:
61  echo "Invalid Option \"$Option\".\n";
62  $showUsage = true;
63  }
64 }
65 
66 if ($showUsage) {
67  global $argv;
68 
69  $usage = "Usage: " . basename($argv[0]) . " [options]
70  Update FOSSology database. Options are:
71  -d {database name} default is 'fossology'
72  -f {output file}
73  -h this help usage";
74  print "$usage\n";
75 } else {
76  if (file_exists($SchemaFilePath) && !@unlink($SchemaFilePath)) {
77  $FailMsg = "Existing schema data file ($SchemaFilePath) could not be removed.";
78  } else {
79  $FailMsg = ExportSchema($SchemaFilePath);
80  }
81 
82  if ($FailMsg !== false) {
83  print "ERROR: $FailMsg \n";
84  exit(1);
85  }
86 }
ExportSchema($filename=NULL)
Export the schema of the connected ($PG_CONN) database to a file in the format readable by GetSchema(...
Definition: libschema.php:1072