Beispiel #1
0
/**
 * Setup of a clean InDefero.
 *
 * It creates all the tables for the application.
 */
function IDF_Migrations_Install_setup($params = null)
{
    $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();
    }
    // Install the permissions
    $perm = new Pluf_Permission();
    $perm->name = 'Project membership';
    $perm->code_name = 'project-member';
    $perm->description = 'Permission given to project members.';
    $perm->application = 'IDF';
    $perm->create();
    $perm = new Pluf_Permission();
    $perm->name = 'Project ownership';
    $perm->code_name = 'project-owner';
    $perm->description = 'Permission given to project owners.';
    $perm->application = 'IDF';
    $perm->create();
    $perm = new Pluf_Permission();
    $perm->name = 'Project authorized users';
    $perm->code_name = 'project-authorized-user';
    $perm->description = 'Permission given to users allowed to access a project.';
    $perm->application = 'IDF';
    $perm->create();
}
Beispiel #2
0
/**
 * Setup of the Plume Framework.
 *
 * It creates all the tables for the framework models.
 */
function Pluf_Migrations_Install_setup($params = null)
{
    $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();
    }
}
Beispiel #3
0
/**
 * Add the download of files.
 */
function IDF_Migrations_3Attachments_up($params = null)
{
    $models = array('IDF_IssueFile');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
}
Beispiel #4
0
/**
 * Add the DB based Git cache.
 */
function IDF_Migrations_11GitCache_up($params = null)
{
    $models = array('IDF_Scm_Cache_Git');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
}
Beispiel #5
0
/**
 * Add the download of files.
 */
function IDF_Migrations_7Wiki_up($params = null)
{
    $models = array('IDF_WikiPage', 'IDF_WikiRevision');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
}
Beispiel #6
0
/**
 * Add the code review.
 */
function IDF_Migrations_8CodeReview_up($params = null)
{
    $models = array('IDF_Review', 'IDF_Review_Patch', 'IDF_Review_FileComment');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
}
Beispiel #7
0
/**
 * Add the download of files.
 */
function IDF_Migrations_4Timeline_up($params = null)
{
    $models = array('IDF_Commit', 'IDF_Timeline');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
}
Beispiel #8
0
/**
 * Add the download of files.
 */
function IDF_Migrations_1Download_up($params = null)
{
    $models = array('IDF_Upload');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
}
Beispiel #9
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();
}
Beispiel #10
0
/**
 * Add the download of files.
 */
function IDF_Migrations_2Search_up($params = null)
{
    $models = array('IDF_Search_Occ');
    $db = Pluf::db();
    $schema = new Pluf_DB_Schema($db);
    foreach ($models as $model) {
        $schema->model = new $model();
        $schema->createTables();
    }
    foreach (Pluf::factory('IDF_Issue')->getList() as $i) {
        IDF_Search::index($i);
    }
}
Beispiel #11
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();
 }
Beispiel #12
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;
}
Beispiel #13
0
/**
 * Add the row permission system.
 */
function Pluf_Migrations_2RowPermission_up($params = null)
{
    $db = Pluf::db();
    $db->begin();
    // Start a transaction
    try {
        $schema = new Pluf_DB_Schema($db);
        $schema->model = new Pluf_RowPermission();
        $schema->createTables();
    } catch (Exception $e) {
        $db->rollback();
        throw $e;
    }
    $db->commit();
}
Beispiel #14
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;
}
Beispiel #15
0
/**
 * Add the search engine.
 */
function Pluf_Migrations_4QueueStats_up($params = null)
{
    $db = Pluf::db();
    $db->begin();
    // Start a transaction
    try {
        $schema = new Pluf_DB_Schema($db);
        foreach (array('Pluf_Search_Stats', 'Pluf_Queue') as $model) {
            $schema->model = new $model();
            $schema->createTables();
        }
    } catch (Exception $e) {
        $db->rollback();
        throw $e;
    }
    $db->commit();
}
Beispiel #16
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();
    }
}
Beispiel #17
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();
 }
Beispiel #18
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();
 }
Beispiel #19
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();
    }