#!/usr/bin/env php
* Copyright © 2015 Strangecode, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/*
* Initialize tables managed by Codebase classes.
*
* @author Quinn Comendant
* @version 1.0
* @since 12 Jul 2015 22:44:58
*/
/********************************************************************
* CONFIG
********************************************************************/
require_once dirname(__FILE__) . '/_config.inc.php';
require_once CODEBASE_PATH . '/lib/ACL.inc.php';
require_once CODEBASE_PATH . '/lib/Auth_SQL.inc.php';
require_once CODEBASE_PATH . '/lib/Lock.inc.php';
require_once CODEBASE_PATH . '/lib/Prefs.inc.php';
require_once CODEBASE_PATH . '/lib/Version.inc.php';
/********************************************************************
* MAIN
********************************************************************/
// Process command line options.
$opt = getopt('fh');
// Get class name.
$class = strtolower(end($_SERVER['argv']));
// Give them a fighting chance. Show the help message.
if ($_SERVER['argc'] <= 1 || isset($opt['h'])) {
help();
exit(1);
}
$app->logMsg(sprintf('Running initDB on %s codebase tables in db %s', $class, $db->getParam('db_name')), LOG_INFO, __FILE__, __LINE__);
if ('all' == $class) {
initClassDB('acl');
initClassDB('auth');
initClassDB('lock');
initClassDB('prefs');
initClassDB('version');
} else {
initClassDB($class);
}
/********************************************************************
* FUNCTIONS
********************************************************************/
/*
*
*
* @access public
* @param
* @return
* @author Quinn Comendant
* @version 1.0
* @since 12 Jul 2015 23:16:02
*/
function help()
{
global $cli_executed;
?>
This script initializes DB tables managed by Codebase classes. If database schema is changed a log message will display.
Usage: [OPTIONS] CLASSNAME
OPTIONS
-f Force recreation of tables, if they already exist.
-h Show this help message.
CLASSNAME is one of:
all Special case: create tables for all classes.
acl Create tables for ACL
auth Create tables for Auth_SQL
lock Create tables for Lock
prefs Create tables for Prefs
version Create tables for Version
* @version 1.0
* @since 12 Jul 2015 23:25:35
*/
function initClassDB($class)
{
global $opt;
switch ($class) {
case 'acl':
// ACL!
$acl =& ACL::getInstance();
$acl->setParam(array('create_table' => true));
$acl->initDB(isset($opt['f']));
break;
case 'auth':
// Auth_SQL!
$auth = new Auth_SQL('codebase');
$auth->setParam(array('create_table' => true));
$auth->initDB(isset($opt['f']));
break;
case 'lock':
// Lock!
$lock =& Lock::getInstance(new Auth_SQL('codebase'));
$lock->setParam(array('create_table' => true));
$lock->initDB(isset($opt['f']));
break;
case 'prefs':
// Prefs!
$prefs = new Prefs('codebase');
$prefs->setParam(array('create_table' => true));
$prefs->initDB(isset($opt['f']));
break;
case 'version':
// Version!
$version = Version::getInstance(new Auth_SQL('codebase'));
$version->setParam(array('create_table' => true));
$version->initDB(isset($opt['f']));
break;
default:
echo "The class $class is not setup to initClassDB.\n";
exit(1);
}
}