Esempio n. 1
0
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();
    }
}
Esempio n. 2
0
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();
    }
}
Esempio n. 3
0
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();
    }
}
Esempio n. 4
0
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();
    }
}
Esempio n. 5
0
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();
    }
}
Esempio n. 6
0
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();
    }
}
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
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();
}
Esempio n. 9
0
/**
 * 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;
}
Esempio n. 10
0
/**
 * 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;
}
Esempio n. 11
0
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();
}
Esempio n. 12
0
/**
 * 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();
    }
}
Esempio n. 13
0
function Todo_Migrations_Install_setup($params = '')
{
    // First we create instances of the two data models in the application.
    $list = new Todo_List();
    $item = new Todo_Item();
    // Get a database connection
    // As the parameters have been given in a standard way in the
    // configuration file we are directly accessing the default db here.
    $db = Pluf::db();
    // Then we create a schema builder to generate the needed tables.
    // The first parameter given to the schema builder is the database
    // connection.
    $schema = new Pluf_DB_Schema($db);
    // Then for each model, we will create the needed tables.
    // To be safe you should ensure that the createTables() call returns
    // true and not an error.
    $schema->model = $list;
    $schema->createTables();
    $schema->model = $item;
    $schema->createTables();
}
Esempio n. 14
0
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();
    }
}
Esempio n. 15
0
 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();
 }
Esempio n. 16
0
 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();
 }
Esempio n. 17
0
    public function testRegroupPlufModelInstance()
    {
        $db = Pluf::db();
        $schema = new Pluf_DB_Schema($db);
        $m = new Pluf_Tests_Model_People_Model();
        $schema->model = $m;
        $schema->createTables();
        $people = array(array('first_name' => 'George', 'last_name' => 'Bush', 'gender' => 'Male'), array('first_name' => 'Bill', 'last_name' => 'Clinton', 'gender' => 'Male'), array('first_name' => 'Margaret', 'last_name' => 'Thatcher', 'gender' => 'Female'), array('first_name' => 'Condoleezza', 'last_name' => 'Rice', 'gender' => 'Female'), array('first_name' => 'Pat', 'last_name' => 'Smith', 'gender' => 'Unknow'));
        foreach ($people as $person) {
            $p = new Pluf_Tests_Model_People_Model();
            foreach ($person as $key => $value) {
                $p->{$key} = $value;
            }
            $p->create();
        }
        unset($p);
        $people_list = Pluf::factory('Pluf_Tests_Model_People_Model')->getList();
        $context = new Pluf_Template_Context(array('people' => $people_list));
        $to_parse = <<<TPL
{regroup \$people, 'gender', 'gender_list'}
<ul>
{foreach \$gender_list as \$gender}
    <li>{\$gender.grouper}:
        <ul>
        {foreach \$gender.list as \$item}
            <li>{\$item.first_name} {\$item.last_name}</li>
        {/foreach}
        </ul>
    </li>
{/foreach}
</ul>
TPL;
        $expected = <<<HTML

<ul>

    <li>Male:
        <ul>
        
            <li>George Bush</li>
        
            <li>Bill Clinton</li>
        
        </ul>
    </li>

    <li>Female:
        <ul>
        
            <li>Margaret Thatcher</li>
        
            <li>Condoleezza Rice</li>
        
        </ul>
    </li>

    <li>Unknow:
        <ul>
        
            <li>Pat Smith</li>
        
        </ul>
    </li>

</ul>
HTML;
        $tpl = $this->getNewTemplate($to_parse);
        $this->assertEqual($expected, $tpl->render($context));
        $schema->dropTables();
    }
Esempio n. 18
0
 /**
  * Get the SQL to generate the indexes of the given model.
  *
  * @param Object Model
  * @return array Array of SQL strings ready to execute.
  */
 function getSqlIndexes($model)
 {
     $index = array();
     foreach ($model->_a['idx'] as $idx => $val) {
         if (!isset($val['col'])) {
             $val['col'] = $idx;
         }
         if ($val['type'] == 'unique') {
             $unique = 'UNIQUE ';
         } else {
             $unique = '';
         }
         $index[$this->con->pfx . $model->_a['table'] . '_' . $idx] = sprintf('CREATE ' . $unique . 'INDEX %s ON %s (%s);', $this->con->pfx . $model->_a['table'] . '_' . $idx, $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($val['col'], $this->con));
     }
     foreach ($model->_a['cols'] as $col => $val) {
         $field = new $val['type']();
         if (isset($val['unique']) and $val['unique'] == true) {
             $index[$this->con->pfx . $model->_a['table'] . '_' . $col . '_unique'] = sprintf('CREATE UNIQUE INDEX %s ON %s (%s);', $this->con->pfx . $model->_a['table'] . '_' . $col . '_unique_idx', $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($col, $this->con));
         }
     }
     return $index;
 }
Esempio n. 19
0
 /**
  * Get the SQL to generate the indexes of the given model.
  *
  * @param Object Model
  * @return array Array of SQL strings ready to execute.
  */
 function getSqlIndexes($model)
 {
     $index = array();
     foreach ($model->_a['idx'] as $idx => $val) {
         if (!isset($val['col'])) {
             $val['col'] = $idx;
         }
         $index[$this->con->pfx . $model->_a['table'] . '_' . $idx] = sprintf('CREATE INDEX `%s` ON `%s` (%s);', $idx, $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($val['col'], $this->con));
     }
     foreach ($model->_a['cols'] as $col => $val) {
         $field = new $val['type']();
         if ($field->type == 'foreignkey') {
             $index[$this->con->pfx . $model->_a['table'] . '_' . $col . '_foreignkey'] = sprintf('CREATE INDEX `%s` ON `%s` (`%s`);', $col . '_foreignkey_idx', $this->con->pfx . $model->_a['table'], $col);
         }
         if (isset($val['unique']) and $val['unique'] == true) {
             $index[$this->con->pfx . $model->_a['table'] . '_' . $col . '_unique'] = sprintf('CREATE UNIQUE INDEX `%s` ON `%s` (%s);', $col . '_unique_idx', $this->con->pfx . $model->_a['table'], Pluf_DB_Schema::quoteColumn($col, $this->con));
         }
     }
     return $index;
 }