- Timestamp:
- Feb 27, 2017 2:13:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/init_codebase_tables.cli.php
r560 r573 24 24 * 25 25 * @author Quinn Comendant <quinn@strangecode.com> 26 * @version 1.027 * @since 12 Jul 2015 22:44:5826 * @version 2.0 27 * @since 05 Mar 2016 19:12:09 28 28 */ 29 30 /********************************************************************31 * CONFIG32 ********************************************************************/33 34 require_once dirname(__FILE__) . '/_config.inc.php';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';40 29 41 30 /******************************************************************** … … 44 33 45 34 // Process command line options. 46 $opt = getopt('fh ');35 $opt = getopt('fhc:'); 47 36 48 // Get class name.37 // Get name of class to initialize (or 'all' for all). 49 38 $class = strtolower(end($_SERVER['argv'])); 50 39 … … 55 44 } 56 45 57 $app->logMsg(sprintf('Running initDB on %s codebase tables in db %s', $class, $db->getParam('db_name')), LOG_INFO, __FILE__, __LINE__); 46 if (isset($opt['c']) && is_file($opt['c'])) { 47 require_once $opt['c']; 48 $app->logMsg(sprintf('Loaded custom config file: %s', $opt['c']), LOG_INFO, __FILE__, __LINE__); 49 } 50 require_once dirname(__FILE__) . '/_config.inc.php'; 58 51 59 52 if ('all' == $class) { … … 63 56 initClassDB('prefs'); 64 57 initClassDB('version'); 58 initClassDB('session'); 65 59 } else { 66 60 initClassDB($class); 67 61 } 68 62 63 $app->stop(); 64 die; 69 65 70 66 /******************************************************************** … … 92 88 OPTIONS 93 89 94 -f Force recreation of tables, if they already exist. 95 -h Show this help message. 90 -c FILE Path to include custom site _config.inc.php file. 91 -f Force recreation of tables, if they already exist. WARNING: this will delete existing records. 92 -h Show this help message. 96 93 97 94 CLASSNAME is one of: … … 103 100 prefs Create tables for Prefs 104 101 version Create tables for Version 102 session Create tables for DBSessionHandler 105 103 <?php 106 104 } … … 119 117 { 120 118 global $opt; 119 $app =& App::getInstance(); 120 $db =& DB::getInstance(); 121 122 $app->logMsg(sprintf('Running %s->initDB() on database %s', $class, $db->getParam('db_name')), LOG_INFO, __FILE__, __LINE__); 121 123 122 124 switch ($class) { 123 125 case 'acl': 124 126 // ACL! 127 require_once CODEBASE_PATH . '/lib/ACL.inc.php'; 125 128 $acl =& ACL::getInstance(); 126 129 $acl->setParam(array('create_table' => true)); … … 130 133 case 'auth': 131 134 // Auth_SQL! 135 require_once CODEBASE_PATH . '/lib/Auth_SQL.inc.php'; 132 136 $auth = new Auth_SQL('codebase'); 133 $auth->setParam(array( 134 'create_table' => true, 135 'abuse_detection' => true, 136 )); 137 $auth->setParam(array('create_table' => true)); 138 if (!isset($opt['c'])) { 139 // User didn't provide custom config. Use sane defaults. 140 $auth->setParam(array('abuse_detection' => true)); 141 } 137 142 $auth->initDB(isset($opt['f'])); 138 143 break; … … 140 145 case 'lock': 141 146 // Lock! 147 require_once CODEBASE_PATH . '/lib/Lock.inc.php'; 142 148 $lock =& Lock::getInstance(new Auth_SQL('codebase')); 143 149 $lock->setParam(array('create_table' => true)); … … 147 153 case 'prefs': 148 154 // Prefs! 155 require_once CODEBASE_PATH . '/lib/Prefs.inc.php'; 149 156 $prefs = new Prefs('codebase'); 150 157 $prefs->setParam(array('create_table' => true)); … … 154 161 case 'version': 155 162 // Version! 163 require_once CODEBASE_PATH . '/lib/Version.inc.php'; 156 164 $version = Version::getInstance(new Auth_SQL('codebase')); 157 165 $version->setParam(array('create_table' => true)); … … 159 167 break; 160 168 169 case 'session': 170 // DBSessionHandler! 171 172 // We need to hack the app to allow sessions to run in a CLI. 173 $app->stop(); 174 $app->cli = false; 175 $app->setParam(array('enable_session' => true)); 176 $app->start(); 177 178 if (!isset($opt['c'])) { 179 // User didn't provide custom config. Use sane defaults. 180 require_once CODEBASE_PATH . '/lib/DBSessionHandler.inc.php'; 181 $db_session = new DBSessionHandler($app->db, array( 182 'db_table' => 'session_tbl', 183 'create_table' => true, 184 )); 185 $db_session->initDB(isset($opt['f'])); 186 } else if (true === $app->getParam('enable_db_session_handler') && true === $app->getParam('enable_db') && isset($app->db_session)) { 187 // Only init if db_session is enabled in config. 188 $app->db_session->initDB(isset($opt['f'])); 189 } 190 break; 191 161 192 default: 162 echo "The class $class is not setup to initClassDB .\n";193 echo "The class $class is not setup to initClassDB().\n"; 163 194 exit(1); 164 195 }
Note: See TracChangeset
for help on using the changeset viewer.