/** * Update schedules (last run) * * @param Object $logger * @param array $completed_processes * * @throws \Comodojo\Exception\DatabaseException */ public static final function updateSchedules($logger, $completed_processes) { if (empty($completed_processes)) { $logger->info("No schedule to update, exiting"); return; } try { $db = new EnhancedDatabase(EXTENDER_DATABASE_MODEL, EXTENDER_DATABASE_HOST, EXTENDER_DATABASE_PORT, EXTENDER_DATABASE_NAME, EXTENDER_DATABASE_USER, EXTENDER_DATABASE_PASS); $db->tablePrefix(EXTENDER_DATABASE_PREFIX)->autoClean(); foreach ($completed_processes as $process) { $db->table(EXTENDER_DATABASE_TABLE_JOBS)->keys("lastrun")->values($process[3])->where('id', '=', $process[6])->update(); } } catch (DatabaseException $de) { unset($db); throw $de; } unset($db); Cache::purge(); Planner::release(); }
private static function pushDefaultContent() { try { $db = new EnhancedDatabase(EXTENDER_DATABASE_MODEL, EXTENDER_DATABASE_HOST, EXTENDER_DATABASE_PORT, EXTENDER_DATABASE_NAME, EXTENDER_DATABASE_USER, EXTENDER_DATABASE_PASS); $db->tablePrefix(EXTENDER_DATABASE_PREFIX); $db->autoClean(); // admin role $admin_role_id = $db->table('roles')->keys(array('name', 'description'))->values(array('admin', 'Default administrator role'))->store()->getInsertId(); $authentication_id = $db->table('authentication')->keys(array('name', 'description', 'class'))->values(array('local', 'Local Authentication Provider', '\\Comodojo\\Authentication\\Provider\\LocalProvider'))->store()->getInsertId(); $admin_pwd = password_hash('comodojo', PASSWORD_DEFAULT); $admin_user_id = $db->table('users')->keys(array('username', 'password', 'displayname', 'mail', 'authentication', 'enabled', 'primaryrole'))->values(array('admin', $admin_pwd, 'Administrator', 'administrator@localhost', $authentication_id, 1, $admin_role_id))->store()->getInsertId(); $db->table('users_to_roles')->keys(array('user', 'role'))->values(array($admin_user_id, $admin_role_id))->store(); } catch (DatabaseException $de) { unset($db); throw new ShellException("Database error: " . $de->getMessage()); } unset($db); }
use Comodojo\Exception\DatabaseException; use Comodojo\Database\Database; use Comodojo\Database\EnhancedDatabase; use Comodojo\Database\QueryBuilder\Column; $query_output_pattern = ' <h1> __NAME__ </h1> <p> Query should like: </p> <pre><code> __TEXT__ </code></pre> <p> QueryBuilder returns: </p> <pre><code> __BUILDER__ </code></pre> '; $query_case = array(); try { $db = new EnhancedDatabase(COMODOJO_DB_MODEL, COMODOJO_DB_HOST, COMODOJO_DB_PORT, COMODOJO_DB_NAME, COMODOJO_DB_USER, COMODOJO_DB_PASSWORD); $db->autoClean(); array_push($query_case, array('name' => "Simple SELECT (GET)", 'text' => "SELECT this,is FROM test", 'builder' => $db->table('test')->keys(array('this', 'is'))->getQuery("GET"))); array_push($query_case, array('name' => "Simple SELECT DISTINCT (GET)", 'text' => "SELECT DISTINCT this,is FROM test", 'builder' => $db->table('test')->distinct()->keys(array('this', 'is'))->getQuery("GET"))); array_push($query_case, array('name' => "Simple SELECT with simple where condition (GET)", 'text' => "...", 'builder' => $db->table('test')->keys(array('this', 'is'))->where('this', '=', 'test')->getQuery("GET"))); array_push($query_case, array('name' => "Simple SELECT with double where condition (GET)", 'text' => "...", 'builder' => $db->table('test')->keys(array('this', 'is'))->where('this', '=', 'test')->andWhere('is', '!=', 'foo')->getQuery("GET"))); array_push($query_case, array('name' => "Simple SELECT with complex where condition (GET)", 'text' => "...", 'builder' => $db->table('test')->keys(array('this', 'is'))->where(array('this', 'LIKE', 'test%'), 'OR', array('this', 'IN', array(1, 10, 'boo', 'koo')))->orWhere('is', '!=', 'foo')->getQuery("GET"))); array_push($query_case, array('name' => "Simple SELECT with very complex where condition (GET)", 'text' => "...", 'builder' => $db->table('test')->keys(array('this', 'is', 'bla', 'cra'))->where(array('this', 'LIKE', 'test%'), 'OR', array('this', 'IN', array(1, 10, 'boo', 'koo')))->orWhere('is', '!=', 'foo')->andWhere(array('bla', 'NOT BETWEEN', array(1, 10000)), 'AND', array('cra', 'IS NOT', null))->getQuery("GET"))); array_push($query_case, array('name' => "SELECT with inner join condition (GET)", 'text' => "...", 'builder' => $db->table('test')->keys(array('this', 'is'))->join('INNER', 'test2', 't2')->getQuery("GET"))); $column_1 = new Column('foo', 'STRING'); $column_2 = new Column('koo', 'INTEGER'); $column_3 = new Column('id', 'INTEGER'); array_push($query_case, array('name' => "CREATE table", 'text' => "...", 'builder' => $db->column($column_3->length(32)->unsigned()->notNull()->autoIncrement()->primaryKey())->column($column_1->length(128)->defaultValue(NULL))->column($column_2->length(64)->notNull()->unsigned())->getQuery("CREATE", array("name" => 'testTable', "if_not_exists" => true, "engine" => null)))); array_push($query_case, array('name' => "DROP table", 'text' => "...", 'builder' => $db->table('testTable')->getQuery("DROP"))); array_push($query_case, array('name' => "EMPTY table", 'text' => "...", 'builder' => $db->table('testTable')->getQuery("EMPTY"))); } catch (DatabaseException $de) { die("comodojo exception: " . $de->getMessage()); } catch (Exception $e) {