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

Last change on this file since 532 was 532, checked in by anonymous, 9 years ago

Added common config for codebase cli scripts. Changed behavior of db_auth.json loading. validSignature() now fails on empty string.

  • Property svn:executable set to *
File size: 4.2 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/lib/ACL.inc.php';
36require_once 'codebase/lib/Auth_SQL.inc.php';
37require_once 'codebase/lib/Lock.inc.php';
38require_once 'codebase/lib/Prefs.inc.php';
39require_once 'codebase/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
57if ('all' == $class) {
58    initClassDB('acl');
59    initClassDB('auth');
60    initClassDB('lock');
61    initClassDB('prefs');
62    initClassDB('version');
63} else {
64    initClassDB($class);
65}
66
67
68/********************************************************************
69* FUNCTIONS
70********************************************************************/
71
72/*
73*
74*
75* @access   public
76* @param
77* @return
78* @author   Quinn Comendant <quinn@strangecode.com>
79* @version  1.0
80* @since    12 Jul 2015 23:16:02
81*/
82function help()
83{
84    global $this_script;
85    ?>
86This script initializes DB tables managed by Codebase classes.
87
88Usage: <?php echo $this_script; ?> [OPTIONS] CLASSNAME
89
90OPTIONS
91
92    -f  Force recreation of tables, if they already exist.
93    -h  Show this help message.
94
95CLASSNAME is one of:
96
97    all         Special case: create tables for all classes.
98    acl         Create tables for ACL
99    auth        Create tables for Auth_SQL
100    lock        Create tables for Lock
101    prefs       Create tables for Prefs
102    version     Create tables for Version
103<?php
104}
105
106/*
107*
108*
109* @access   public
110* @param
111* @return
112* @author   Quinn Comendant <quinn@strangecode.com>
113* @version  1.0
114* @since    12 Jul 2015 23:25:35
115*/
116function initClassDB($class)
117{
118    global $opt;
119
120    switch ($class) {
121        case 'acl':
122            // ACL!
123            $acl =& ACL::getInstance();
124            $acl->setParam(array('create_table' => true));
125            $acl->initDB(isset($opt['f']));
126            break;
127
128        case 'auth':
129            // Auth_SQL!
130            $auth = new Auth_SQL('codebase');
131            $auth->setParam(array('create_table' => true));
132            $auth->initDB(isset($opt['f']));
133            break;
134
135        case 'lock':
136            // Lock!
137            $lock =& Lock::getInstance(new Auth_SQL('codebase'));
138            $lock->setParam(array('create_table' => true));
139            $lock->initDB(isset($opt['f']));
140            break;
141
142        case 'prefs':
143            // Prefs!
144            $prefs = new Prefs('codebase');
145            $prefs->setParam(array('create_table' => true));
146            $prefs->initDB(isset($opt['f']));
147            break;
148
149        case 'version':
150            // Version!
151            $version = Version::getInstance(new Auth_SQL('codebase'));
152            $version->setParam(array('create_table' => true));
153            $version->initDB(isset($opt['f']));
154            break;
155
156        default:
157            echo "The class $class is not setup to initClassDB.\n";
158            exit(1);
159    }
160}
Note: See TracBrowser for help on using the repository browser.