/** * Construct the constructor with a default condition. */ function __construct($base = '', $args = array()) { $this->db = Pluf::db(); if (strlen($base) > 0) { $this->Q($base, $args); } }
/** * Get an item to process. * * @return mixed False if no item to proceed. */ public static function getItem() { $item = false; $db = Pluf::db(); $db->begin(); // In a transaction to not process the same item at // the same time from to processes. $gqueue = new Pluf_Queue(); $items = $gqueue->getList(array('filter' => $db->qn('lock') . '=0', 'order' => 'creation_dtime ASC')); if ($items->count() > 0) { $item = $items[0]; $item->lock = 1; $item->update(); } $db->commit(); if ($item === false) { return false; } // try to get the corresponding object $obj = Pluf::factory($item->model_class, $item->model_id); if ($obj->id != $item->model_id) { $obj = null; } return array('queue' => $item, 'item' => $obj); }
protected function tearDown() { $db = Pluf::db(); $schema = Pluf::factory('Pluf_DB_Schema', $db); $m1 = new TestFormModel(); $schema->model = $m1; $schema->dropTables(); }
protected function setUp() { Pluf::start(dirname(__FILE__) . '/../conf/pluf.config.php'); $this->db = Pluf::db(); if ($this->db->engine != 'SQLite') { $this->markTestSkipped('Only to be run with the SQLite DB engine'); } }
function tearDown() { $db = Pluf::db(); $schema = Pluf::factory('Pluf_DB_Schema', $db); $m = new Pluf_Permission(); $schema->model = $m; $schema->dropTables(); }
function IDF_Migrations_4Timeline_down($params = null) { $models = array('IDF_Timeline', 'IDF_Commit'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function IDF_Migrations_7Wiki_down($params = null) { $models = array('IDF_WikiRevision', 'IDF_WikiPage'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function IDF_Migrations_8CodeReview_down($params = null) { $models = array('IDF_Review_FileComment', 'IDF_Review_Patch', 'IDF_Review'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function Pluf_Migrations_Install_teardown($params = null) { $models = array('Pluf_Queue', 'Pluf_Search_Stats', 'Pluf_Search_Occ', 'Pluf_Search_Word', 'Pluf_RowPermission', 'Pluf_Permission', 'Pluf_Message', Pluf::f('pluf_custom_group', 'Pluf_Group'), Pluf::f('pluf_custom_user', 'Pluf_User'), 'Pluf_Session', 'Pluf_DB_SchemaInfo'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function IDF_Migrations_1Download_down($params = null) { $models = array('IDF_Upload'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function IDF_Migrations_3Attachments_down($params = null) { $models = array('IDF_IssueFile'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function IDF_Migrations_9ShortDescription_down($params = null) { $table = Pluf::factory('IDF_Project')->getSqlTable(); $sql = array(); $sql['PostgreSQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN "shortdesc"'; $sql['MySQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN `shortdesc`'; $db = Pluf::db(); $engine = Pluf::f('db_engine'); if (!isset($sql[$engine])) { throw new Exception('SQLite complex migration not supported.'); } $db->execute($sql[$engine]); }
function IDF_Migrations_12DownloadDesc_down($params = null) { $table = Pluf::factory('IDF_Upload')->getSqlTable(); $sql = array(); $sql['PostgreSQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN "changelog"'; $sql['MySQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN `changelog`'; $db = Pluf::db(); $engine = Pluf::f('db_engine'); if (!isset($sql[$engine])) { throw new Exception('SQLite complex migration not supported.'); } $db->execute($sql[$engine]); }
function testCreate() { $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); $m = new Pluf_Tests_Model_CompressedField_Model(); $schema->model = $m; $schema->createTables(); $m->compressed = 'Youplaboum'; $m->create(); $this->assertEqual(1, $m->id); $m = new Pluf_Tests_Model_CompressedField_Model(1); $this->assertEqual('Youplaboum', $m->compressed); $schema->dropTables(); }
/** * Add the download of files. */ function IDF_Migrations_5DescToText_up($params = null) { $table = Pluf::factory('IDF_Conf')->getSqlTable(); $sql = array(); $sql['PostgreSQL'] = 'ALTER TABLE ' . $table . ' ALTER vdesc TYPE text'; $sql['MySQL'] = 'ALTER TABLE ' . $table . ' CHANGE vdesc TYPE text'; $db = Pluf::db(); $engine = Pluf::f('db_engine'); if (!isset($sql[$engine])) { echo 'Skip SQLite upgrade as not needed.' . "\n"; return; } $db->execute($sql[$engine]); }
function testCreate() { $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); $m = new Pluf_Tests_Model_SlugField_Model(); $schema->model = $m; $schema->createTables(); $m->slug_default_length = 'Pluf, supported by Céondo Ltd.'; $m->create(); $this->assertEqual(1, $m->id); $m = new Pluf_Tests_Model_SlugField_Model(1); $this->assertEqual('pluf-supported-by-ceondo-ltd', $m->slug_default_length); $schema->dropTables(); }
function Pluf_Migrations_2RowPermission_down($params = null) { $db = Pluf::db(); $db->begin(); // Start a transaction try { $schema = new Pluf_DB_Schema($db); $schema->model = new Pluf_RowPermission(); $schema->dropTables(); } catch (Exception $e) { $db->rollback(); throw $e; } $db->commit(); }
/** * Restore IDF from a backup. * * @param string Path to the backup folder * @param string Backup name * @return bool Success */ function IDF_Migrations_Backup_restore($folder, $name) { $models = array('IDF_Project', 'IDF_Tag', 'IDF_Issue', 'IDF_IssueComment', 'IDF_Conf', 'IDF_Upload', 'IDF_Search_Occ', 'IDF_IssueFile', 'IDF_Commit', 'IDF_Timeline', 'IDF_WikiPage', 'IDF_WikiRevision', 'IDF_Review', 'IDF_Review_Patch', 'IDF_Review_Comment', 'IDF_Review_FileComment', 'IDF_Key', 'IDF_Scm_Cache_Git', 'IDF_Queue', 'IDF_Gconf'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->createTables(); } $full_data = json_decode(file_get_contents(sprintf('%s/%s-IDF.json', $folder, $name)), true); foreach ($full_data as $model => $data) { Pluf_Test_Fixture::load($data, false); } return true; }
/** * Restore Pluf from a backup. * * @param string Path to the backup folder * @param string Backup name * @return bool Success */ function Pluf_Migrations_Backup_restore($folder, $name) { $models = array('Pluf_DB_SchemaInfo', 'Pluf_Session', Pluf::f('pluf_custom_user', 'Pluf_User'), Pluf::f('pluf_custom_group', 'Pluf_Group'), 'Pluf_Message', 'Pluf_Permission', 'Pluf_RowPermission', 'Pluf_Search_Word', 'Pluf_Search_Occ', 'Pluf_Search_Stats', 'Pluf_Queue'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->createTables(); } $full_data = json_decode(file_get_contents(sprintf('%s/%s-Pluf.json', $folder, $name)), true); foreach ($full_data as $model => $data) { Pluf_Test_Fixture::load($data, false); } return true; }
function Todo_Migrations_Install_teardown($params = '') { // The uninstallation is the reverse of the installation. // We create the data models the same way, but instead of calling // createTables() we call dropTables() // You can see that without all the comments, you do not have a // lot of lines of code. $list = new Todo_List(); $item = new Todo_Item(); $db = Pluf::db(); $schema = Pluf::factory('Pluf_DB_Schema', $db); $schema->model = $list; $schema->dropTables(); $schema->model = $item; $schema->dropTables(); }
function Pluf_Migrations_5UserDetails_down($params = null) { $db = Pluf::db(); $db->begin(); // Start a transaction try { $user_model = Pluf::f('pluf_custom_user', 'Pluf_User'); $guser = new $user_model(); $table = $guser->getSqlTable(); $sql = 'ALTER TABLE ' . $table . "\n" . 'DROP COLUMN language,' . "\n" . 'DROP COLUMN timezone' . "\n"; $db->execute($sql); } catch (Exception $e) { $db->rollback(); throw $e; } $db->commit(); }
/** * Remove the old review and add the new one. * * This is a destructive operation. */ function IDF_Migrations_13NewReview_up($params = null) { $extra = Pluf::f('db_engine') == 'PostgreSQL' ? ' CASCADE' : ''; $pfx = Pluf::f('db_table_prefix'); $tables = array('idf_review_filecomments', 'idf_review_patches', 'idf_review_pluf_user_assoc', 'idf_review_idf_tag_assoc', 'idf_reviews'); $db = Pluf::db(); foreach ($tables as $table) { $db->execute('DROP TABLE IF EXISTS ' . $pfx . $table . $extra); } $models = array('IDF_Review', 'IDF_Review_Patch', 'IDF_Review_Comment', 'IDF_Review_FileComment'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->createTables(); } }
function Pluf_Migrations_4QueueStats_down($params = null) { $db = Pluf::db(); $db->begin(); // Start a transaction try { $schema = new Pluf_DB_Schema($db); foreach (array('Pluf_Queue', 'Pluf_Search_Stats') as $model) { $schema->model = new $model(); $schema->dropTables(); } } catch (Exception $e) { $db->rollback(); throw $e; } $db->commit(); }
function IDF_Migrations_6PrivateProject_down($params = null) { $perm = Pluf_Permission::getFromString('IDF.project-authorized-user'); if ($perm) { $perm->delete(); } $table = Pluf::factory('IDF_Project')->getSqlTable(); $sql = array(); $sql['PostgreSQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN "private"'; $sql['MySQL'] = 'ALTER TABLE ' . $table . ' DROP COLUMN `private`'; $db = Pluf::db(); $engine = Pluf::f('db_engine'); if (!isset($sql[$engine])) { throw new Exception('SQLite complex migration not supported.'); } $db->execute($sql[$engine]); }
function IDF_Migrations_Install_teardown($params = null) { $perm = Pluf_Permission::getFromString('IDF.project-member'); if ($perm) { $perm->delete(); } $perm = Pluf_Permission::getFromString('IDF.project-owner'); if ($perm) { $perm->delete(); } $perm = Pluf_Permission::getFromString('IDF.project-authorized-user'); if ($perm) { $perm->delete(); } $models = array('IDF_Gconf', 'IDF_Queue', 'IDF_Scm_Cache_Git', 'IDF_Key', 'IDF_Review_FileComment', 'IDF_Review_Comment', 'IDF_Review_Patch', 'IDF_Review', 'IDF_WikiRevision', 'IDF_WikiPage', 'IDF_Timeline', 'IDF_IssueFile', 'IDF_Search_Occ', 'IDF_Upload', 'IDF_Conf', 'IDF_IssueComment', 'IDF_Issue', 'IDF_Tag', 'IDF_Commit', 'IDF_Project'); $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); foreach ($models as $model) { $schema->model = new $model(); $schema->dropTables(); } }
function testCreate() { $db = Pluf::db(); $schema = new Pluf_DB_Schema($db); $m = new Pluf_Tests_Model_Schema_Model(); $schema->model = $m; $schema->createTables(); $m->column1 = 'Youplaboum'; $m->column2 = 'Youplaboum'; $m->column3 = 'Youplaboum'; $m->create(); $this->assertEqual(1, $m->id); $m = new Pluf_Tests_Model_Schema_Model(); $m->column1 = 'Youplaboum'; $m->column2 = 'Youplaboum'; $m->column3 = 'Youplaboum'; try { $m->create(); $this->assertNotEqual(2, $m->id, 'Should not be able to create.'); } catch (Exception $e) { // do nothing } $schema->dropTables(); }
/** * Get a database connection. */ function _getConnection() { static $con = null; if ($this->_con !== null) { return $this->_con; } if ($con !== null) { $this->_con = $con; return $this->_con; } $this->_con =& Pluf::db($this); $con = $this->_con; return $this->_con; }
protected function setUp() { Pluf::start(dirname(__FILE__) . '/../conf/pluf.config.php'); $this->db =& Pluf::db(); }
public function users($request, $match, $not_validated = false) { $pag = new Pluf_Paginator(new Pluf_User()); $db =& Pluf::db(); $true = Pluf_DB_BooleanToDb(true, $db); if ($not_validated) { $pag->forced_where = new Pluf_SQL('first_name = \'---\' AND active!=' . $true); $title = __('Not Validated User List'); $pag->action = 'IDF_Views_Admin::usersNotValidated'; } else { $pag->forced_where = new Pluf_SQL('first_name != \'---\''); $title = __('User List'); $pag->action = 'IDF_Views_Admin::users'; } $pag->class = 'recent-issues'; $pag->summary = __('This table shows the users in the forge.'); $pag->edit_action = array('IDF_Views_Admin::userUpdate', 'id'); $pag->sort_order = array('login', 'ASC'); $list_display = array('login' => __('login'), array('last_name', 'Pluf_Paginator_ToString', __('Name')), array('staff', 'IDF_Views_Admin_bool', __('Staff')), array('administrator', 'IDF_Views_Admin_bool', __('Admin')), array('active', 'IDF_Views_Admin_bool', __('Active')), array('last_login', 'Pluf_Paginator_DateYMDHM', __('Last Login'))); $pag->extra_classes = array('', '', 'a-c', 'a-c', 'a-c', 'a-c'); $pag->configure($list_display, array('login', 'last_name', 'email'), array('login', 'last_login')); $pag->items_per_page = 50; $pag->no_results_text = __('No users were found.'); $pag->setFromRequest($request); return Pluf_Shortcuts_RenderToResponse('idf/gadmin/users/index.html', array('page_title' => $title, 'users' => $pag, 'not_validated' => $not_validated), $request); }
/** * Get the current version of the app. * * @param string Application. * @return int Version. */ public function getAppVersion($app) { try { $db =& Pluf::db(); $res = $db->select('SELECT version FROM ' . $db->pfx . 'schema_info WHERE application=' . $db->esc($app)); return (int) $res[0]['version']; } catch (Exception $e) { // We should not be here, only in the case of nothing // installed. I am not sure if this is a good way to // handle this border case anyway. Maybe better to have an // 'install' method to run all the migrations in order. return 0; } }