Exemple #1
0
 protected function runSqlQuery()
 {
     $sql = Request::get('SQLTEXT');
     if (!preg_match('/^(SELECT|SHOW|DESCRIBE).*$/im', $sql)) {
         $html = '<br><b>SELECT SQL only</b>';
     } else {
         $html = DBTable::factory(DB::DEF, $sql, null, DB::FETCH_ASSOC)->__toString();
     }
     return $this->askSqlQuery() . '<br/>' . $html;
 }
Exemple #2
0
 public static function migrate()
 {
     $maxRun = 0;
     $runItems = [];
     foreach (DBTable::factory(DB::DEF, 'SELECT * FROM tblMigration') as $row) {
         if ((int) $row['fldRun'] > $maxRun) {
             $maxRun = (int) $row['fldRun'];
         }
         if (!isset($runItems[$row['fldClass']])) {
             $runItems[$row['fldClass']] = [];
         }
         $runItems[$row['fldClass']][] = $row['fldMethod'];
     }
     $maxRun += 1;
     $html = '';
     // Go through all the migration classes
     foreach (Cfg::get('migration', []) as $migrationClass) {
         $clazz = new \ReflectionClass($migrationClass);
         // If new class then just add empty list
         if (!isset($runItems[$migrationClass])) {
             $runItems[$migrationClass] = [];
         }
         // get a list of methods to run
         $methodList = [];
         foreach ($clazz->getMethods() as $method) {
             if (in_array($method->name, $runItems[$migrationClass])) {
                 continue;
             }
             if (strpos($method->name, 'migrate') !== 0) {
                 continue;
             }
             // Add the name to the list
             $methodList[] = $method->name;
         }
         // Sort so that it will be date ordered
         sort($methodList);
         foreach ($methodList as $method) {
             if (($result = call_user_func([$migrationClass, $method])) === false) {
                 $html .= "There is a problem running {$migrationClass}::{$method}<br/>\n";
             } else {
                 $html .= $result;
                 DB::exec(DB::DEF, 'INSERT INTO tblMigration (fldMigrationID,fldRun,fldClass,fldMethod) VALUES (?,?,?,?)', [DBMaintenance::dbNextNumber(DB::DEF, 'tblMigration'), $maxRun, $migrationClass, $method]);
             }
         }
     }
     return $html;
 }
Exemple #3
0
    public function manageGroupsCallBack($id, $key)
    {
        $concat = DB::driver() == DB::MYSQL ? "CONCAT(fldFirstName,' ',fldLastName)" : "fldFirstName || ' ' || fldLastName";
        $sql = <<<SQL
SELECT {$concat}
FROM tblUser
WHERE fldUserID IN ( SELECT fldUserID
                     FROM tblUserGroupMap
                     WHERE fldGroupID=? )
SQL;
        $users = DBTable::factory(DB::DEF, $sql, $key, DB::FETCH_NUM)->getColumn(0);
        $userList = join(', ', $users);
        if ($userList == '') {
            $userList = '*None*';
        }
        $this->resp->action(__CLASS__ . "->manageUsersToGroups()")->set('IDX', $id)->set('KEY', $key);
        return Tag::hRef('?' . $this->resp->toUrl(), $userList, ['title' => 'Click here to edit the users in this group']);
    }
Exemple #4
0
 private static function getGroupIDs($uid)
 {
     $qry = 'SELECT fldGroupID FROM tblUserGroupMap WHERE fldUserID=?';
     $groups = DBTable::factory(DB::DEF, $qry, $uid, DB::FETCH_NUM)->getColumn(0);
     $groups[] = DB::oneValue(DB::DEF, 'SELECT fldGroupID FROM tblGroup LIMIT 1');
     return $groups;
 }