Exemplo n.º 1
0
 public static function initialize()
 {
     $dbType = Cfg::get('local-driver');
     switch ($dbType) {
         case DB::SQLITE:
             $dbFileName = Cfg::get('local-host');
             echo "Checking that the file {$dbFileName} exists\n";
             if (file_exists($dbFileName)) {
                 echo "Database exists ({$dbFileName})\n";
             } else {
                 echo "Creating empty database\n";
                 touch($dbFileName);
             }
             break;
         case DB::MYSQL:
             $fldHostName = Cfg::get('local-host');
             $fldDBName = Cfg::get('local-db');
             $fldUsername = Cfg::get('local-user');
             $fldPassword = Cfg::get('local-pass');
             try {
                 $dbh = new \PDO("mysql:host={$fldHostName}", $fldUsername, $fldPassword);
                 $dbh->exec("CREATE DATABASE IF NOT EXISTS {$fldDBName}") or die(print_r($dbh->errorInfo(), true));
             } catch (PDOException $e) {
                 die("DB ERROR: " . $e->getMessage());
             }
             break;
         default:
             die("Unsupported DB Type: {$dbType}");
     }
     if (count(\Jackbooted\DB\DBMaintenance::getTableList()) == 0) {
         // Put in the base data
         $sqlFileName = Cfg::get('tmp_path') . '/base_database.sql';
         if (file_exists($sqlFileName)) {
             echo "Running the commands in {$sqlFileName} against the database\n";
             foreach (explode(';', file_get_contents($sqlFileName)) as $statement) {
                 DB::exec(DB::DEF, $statement);
             }
         } else {
             die("Base Database file does not exists ({$sqlFileName}) aborting\n");
         }
     } else {
         die("Database already seems to be set up.");
     }
     echo "audititing Table - AlertsDAO\n";
     (new \App\Models\AlertsDAO())->auditTable();
     return '';
 }
Exemplo n.º 2
0
 public function index($tName = '')
 {
     if (($tableName = Request::get('tblName', $tName)) == '') {
         return '';
     }
     $crud = CRUD::factory($tableName, ['topPager' => false])->copyVarsFromRequest('tblName');
     if (preg_match('/^tblMod([A-Z]+[a-z]+)/', $tableName, $matches)) {
         foreach (Cfg::get('modules', []) as $moduleClass) {
             eval($moduleClass . '::' . Module::CRUD_MOD . '($crud);');
         }
     } else {
         switch ($tableName) {
             case 'tblNextNumber':
                 $crud->setColDisplay('fldTable', [CRUD::SELECT, DBMaintenance::getTableList(), true]);
                 break;
             case 'tblSecPrivUserMap':
                 $userSql = DB::driver() == DB::MYSQL ? Admin::USER_SQL_MYSQL : Admin::USER_SQL_MYSQL;
                 $crud->setColDisplay('fldUserID', [CRUD::SELECT, $userSql, true]);
                 $crud->setColDisplay('fldGroupID', [CRUD::SELECT, Admin::GROUP_SQL, true]);
                 $crud->setColDisplay('fldPrivilegeID', [CRUD::SELECT, Admin::PRIV_SQL, true]);
                 $crud->setColDisplay('fldLevelID', [CRUD::SELECT, Admin::LEVEL_SQL]);
                 break;
             case 'tblUserGroupMap':
                 $userSql = DB::driver() == DB::MYSQL ? Admin::USER_SQL_MYSQL : Admin::USER_SQL_SQLITE;
                 $crud->setColDisplay('fldUserID', [CRUD::SELECT, $userSql, true]);
                 $crud->setColDisplay('fldGroupID', [CRUD::SELECT, Admin::GROUP_SQL, true]);
                 break;
             case 'tblUser':
                 $crud->setColDisplay('fldLevel', [CRUD::SELECT, Admin::LEVEL_SQL]);
                 $crud->setColDisplay('fldTimeZone', [CRUD::SELECT, Admin::TZ_SQL]);
                 break;
         }
     }
     $resp = Response::factory()->set('tblName', $tableName);
     return Tag::hTag('b') . 'Editing Table: ' . $tableName . Tag::_hTag('b') . ' ' . Tag::hRef('ajax.php?' . $resp->action(__CLASS__ . '->csv()'), 'CSV') . ' ' . Tag::hRef('ajax.php?' . $resp->action(__CLASS__ . '->xls()'), 'XLS') . $crud->index();
 }
Exemplo n.º 3
0
 protected function updateNextNumber()
 {
     $backMsg = '';
     $tableList = DBMaintenance::getTableList();
     foreach ($tableList as $t) {
         // Make sure that it is our table and not something else
         if (preg_match('/^tbl.*$/', $t)) {
             continue;
         }
         if (DBMaintenance::addTableToNextNumber($t, 'XXX000000')) {
             $backMsg .= '<br/>Added ' . $t;
         }
     }
     if ($backMsg == '') {
         $backMsg = '<br/>No Updates required';
     }
     return '<b>Updated tblNextNumber</b>' . $backMsg;
 }
Exemplo n.º 4
0
 public function auditTable()
 {
     if (in_array(null, [$this->db, $this->tableName, $this->tableStructure])) {
         return false;
     }
     if (!isset(self::$tableList[$this->db])) {
         self::$tableList[$this->db] = array_flip(DBMaintenance::getTableList());
     }
     if (!isset(self::$tableList[$this->db][$this->tableName])) {
         DB::exec($this->db, $this->tableStructure);
         DBMaintenance::addTableToNextNumber($this->tableName, $this->keyFormat, $this->tableName);
         self::$tableList[$this->db][$this->tableName] = 1;
     }
     return true;
 }