[532] | 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 | |
---|
| 34 | require_once dirname(__FILE__) . '/_config.inc.php'; |
---|
[533] | 35 | require_once CODEBASE_PATH . '/lib/ACL.inc.php'; |
---|
| 36 | require_once CODEBASE_PATH . '/lib/Auth_SQL.inc.php'; |
---|
| 37 | require_once CODEBASE_PATH . '/lib/Lock.inc.php'; |
---|
| 38 | require_once CODEBASE_PATH . '/lib/Prefs.inc.php'; |
---|
| 39 | require_once CODEBASE_PATH . '/lib/Version.inc.php'; |
---|
[532] | 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. |
---|
| 52 | if ($_SERVER['argc'] <= 1 || isset($opt['h'])) { |
---|
| 53 | help(); |
---|
| 54 | exit(1); |
---|
| 55 | } |
---|
| 56 | |
---|
[533] | 57 | $app->logMsg(sprintf('Running initDB on %s codebase tables in db %s', $class, $db->getParam('db_name')), LOG_INFO, __FILE__, __LINE__); |
---|
| 58 | |
---|
[532] | 59 | if ('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 | */ |
---|
| 84 | function help() |
---|
| 85 | { |
---|
[533] | 86 | global $cli_executed; |
---|
[532] | 87 | ?> |
---|
[533] | 88 | This script initializes DB tables managed by Codebase classes. If database schema is changed a log message will display. |
---|
[532] | 89 | |
---|
[533] | 90 | Usage: <?php echo $cli_executed; ?> [OPTIONS] CLASSNAME |
---|
[532] | 91 | |
---|
| 92 | OPTIONS |
---|
| 93 | |
---|
| 94 | -f Force recreation of tables, if they already exist. |
---|
| 95 | -h Show this help message. |
---|
| 96 | |
---|
| 97 | CLASSNAME 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 | */ |
---|
| 118 | function 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('create_table' => true)); |
---|
| 134 | $auth->initDB(isset($opt['f'])); |
---|
| 135 | break; |
---|
| 136 | |
---|
| 137 | case 'lock': |
---|
| 138 | // Lock! |
---|
| 139 | $lock =& Lock::getInstance(new Auth_SQL('codebase')); |
---|
| 140 | $lock->setParam(array('create_table' => true)); |
---|
| 141 | $lock->initDB(isset($opt['f'])); |
---|
| 142 | break; |
---|
| 143 | |
---|
| 144 | case 'prefs': |
---|
| 145 | // Prefs! |
---|
| 146 | $prefs = new Prefs('codebase'); |
---|
| 147 | $prefs->setParam(array('create_table' => true)); |
---|
| 148 | $prefs->initDB(isset($opt['f'])); |
---|
| 149 | break; |
---|
| 150 | |
---|
| 151 | case 'version': |
---|
| 152 | // Version! |
---|
| 153 | $version = Version::getInstance(new Auth_SQL('codebase')); |
---|
| 154 | $version->setParam(array('create_table' => true)); |
---|
| 155 | $version->initDB(isset($opt['f'])); |
---|
| 156 | break; |
---|
| 157 | |
---|
| 158 | default: |
---|
| 159 | echo "The class $class is not setup to initClassDB.\n"; |
---|
| 160 | exit(1); |
---|
| 161 | } |
---|
| 162 | } |
---|