source: trunk/bin/init_codebase_tables.cli.php @ 564

Last change on this file since 564 was 560, checked in by anonymous, 8 years ago

Minor code formatting and comments.

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1#!/usr/bin/env php
2<?php
3/*
4* The Strangecode Codebase - a general application development framework for PHP
5* For details visit the project site: <http://trac.strangecode.com/>
6* Copyright © 2015 Strangecode, LLC
7*
8* This program is free software: you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation, either version 3 of the License, or
11* (at your option) any later version.
12*
13* This program is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16* GNU General Public License for more details.
17*
18* You should have received a copy of the GNU General Public License
19* along with this program.  If not, see <http://www.gnu.org/licenses/>.
20*/
21
22/*
23* Initialize tables managed by Codebase classes.
24*
25* @author   Quinn Comendant <quinn@strangecode.com>
26* @version  1.0
27* @since    12 Jul 2015 22:44:58
28*/
29
30/********************************************************************
31* CONFIG
32********************************************************************/
33
34require_once dirname(__FILE__) . '/_config.inc.php';
35require_once CODEBASE_PATH . '/lib/ACL.inc.php';
36require_once CODEBASE_PATH . '/lib/Auth_SQL.inc.php';
37require_once CODEBASE_PATH . '/lib/Lock.inc.php';
38require_once CODEBASE_PATH . '/lib/Prefs.inc.php';
39require_once CODEBASE_PATH . '/lib/Version.inc.php';
40
41/********************************************************************
42* MAIN
43********************************************************************/
44
45// Process command line options.
46$opt = getopt('fh');
47
48// Get class name.
49$class = strtolower(end($_SERVER['argv']));
50
51// Give them a fighting chance. Show the help message.
52if ($_SERVER['argc'] <= 1 || isset($opt['h'])) {
53    help();
54    exit(1);
55}
56
57$app->logMsg(sprintf('Running initDB on %s codebase tables in db %s', $class, $db->getParam('db_name')), LOG_INFO, __FILE__, __LINE__);
58
59if ('all' == $class) {
60    initClassDB('acl');
61    initClassDB('auth');
62    initClassDB('lock');
63    initClassDB('prefs');
64    initClassDB('version');
65} else {
66    initClassDB($class);
67}
68
69
70/********************************************************************
71* FUNCTIONS
72********************************************************************/
73
74/*
75*
76*
77* @access   public
78* @param
79* @return
80* @author   Quinn Comendant <quinn@strangecode.com>
81* @version  1.0
82* @since    12 Jul 2015 23:16:02
83*/
84function help()
85{
86    global $cli_executed;
87    ?>
88This script initializes DB tables managed by Codebase classes. If database schema is changed a log message will display.
89
90Usage: <?php echo $cli_executed; ?> [OPTIONS] CLASSNAME
91
92OPTIONS
93
94    -f  Force recreation of tables, if they already exist.
95    -h  Show this help message.
96
97CLASSNAME is one of:
98
99    all         Special case: create tables for all classes.
100    acl         Create tables for ACL
101    auth        Create tables for Auth_SQL
102    lock        Create tables for Lock
103    prefs       Create tables for Prefs
104    version     Create tables for Version
105<?php
106}
107
108/*
109*
110*
111* @access   public
112* @param
113* @return
114* @author   Quinn Comendant <quinn@strangecode.com>
115* @version  1.0
116* @since    12 Jul 2015 23:25:35
117*/
118function initClassDB($class)
119{
120    global $opt;
121
122    switch ($class) {
123        case 'acl':
124            // ACL!
125            $acl =& ACL::getInstance();
126            $acl->setParam(array('create_table' => true));
127            $acl->initDB(isset($opt['f']));
128            break;
129
130        case 'auth':
131            // Auth_SQL!
132            $auth = new Auth_SQL('codebase');
133            $auth->setParam(array(
134                'create_table' => true,
135                'abuse_detection' => true,
136            ));
137            $auth->initDB(isset($opt['f']));
138            break;
139
140        case 'lock':
141            // Lock!
142            $lock =& Lock::getInstance(new Auth_SQL('codebase'));
143            $lock->setParam(array('create_table' => true));
144            $lock->initDB(isset($opt['f']));
145            break;
146
147        case 'prefs':
148            // Prefs!
149            $prefs = new Prefs('codebase');
150            $prefs->setParam(array('create_table' => true));
151            $prefs->initDB(isset($opt['f']));
152            break;
153
154        case 'version':
155            // Version!
156            $version = Version::getInstance(new Auth_SQL('codebase'));
157            $version->setParam(array('create_table' => true));
158            $version->initDB(isset($opt['f']));
159            break;
160
161        default:
162            echo "The class $class is not setup to initClassDB.\n";
163            exit(1);
164    }
165}
Note: See TracBrowser for help on using the repository browser.