Ejemplo n.º 1
0
 function test_start()
 {
     $this->installAndIncludeModels(array('Post', 'Tag'));
     $Installer = new AkInstaller();
     @$Installer->dropTable('posts_tags');
     @$Installer->dropTable('posts_users');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'post_tag.php');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'post_user.php');
     $this->installAndIncludeModels(array('Picture', 'Thumbnail', 'Panorama', 'Property', 'PropertyType', 'User'));
 }
Ejemplo n.º 2
0
 public function setup()
 {
     $this->installAndIncludeModels(array('Post', 'Tag', 'Comment'));
     $Installer = new AkInstaller();
     @$Installer->dropTable('posts_tags');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'post_tag.php');
 }
Ejemplo n.º 3
0
 function createTableOnTheFly($model_name, $fields)
 {
     $table_name = AkInflector::tableize($model_name);
     $Installer = new AkInstaller();
     $Installer->dropTable($table_name, array('sequence' => true));
     $Installer->createTable($table_name, $fields, array('timestamp' => false));
 }
 public function test_should_create_and_remove_table()
 {
     $this->installAndIncludeModels(array('Exist' => 'id,order'));
     $Installer = new AkInstaller();
     $this->assertTrue($Installer->tableExists('exists'));
     $Installer->dropTable('exists');
     $this->assertFalse($Installer->tableExists('exists'));
 }
 public function test_should_migrate_integers()
 {
     if (!$this->WeHaveAPostgreSqlEnvironment) {
         return;
     }
     // mimic OLD boolean and integer behavior!
     $this->installAndIncludeModels(array('TestPage' => "id,parent_id n(11.0),is_public n(1)"));
     $from_datadict = $this->db->getColumnDetails('test_pages');
     $this->assertEqual($from_datadict['PARENT_ID']->type, 'numeric');
     $this->assertEqual($from_datadict['PARENT_ID']->max_length, 11);
     $this->assertEqual($from_datadict['PARENT_ID']->scale, 0);
     $this->assertEqual($from_datadict['IS_PUBLIC']->type, 'numeric');
     $this->assertEqual($from_datadict['IS_PUBLIC']->max_length, 1);
     $this->assertEqual($from_datadict['IS_PUBLIC']->scale, 0);
     // we insert some data, not using ActiveRecord
     $this->db->execute('INSERT INTO test_pages (is_public) VALUES (1)');
     $this->db->execute('INSERT INTO test_pages (is_public) VALUES (0)');
     $this->db->execute('INSERT INTO test_pages (parent_id) VALUES (1)');
     // we want is_public = NULL
     $data = $this->db->select('SELECT * FROM test_pages');
     $expected = array(array('id' => 1, 'parent_id' => null, 'is_public' => 1), array('id' => 2, 'parent_id' => null, 'is_public' => 0), array('id' => 3, 'parent_id' => 1, 'is_public' => null));
     $this->assertEqual($data, $expected);
     // now we migrate
     $installer = new AkInstaller();
     $installer->transactionStart();
     // if the following fails, you're on Postgre 7 and you have to do it just like we'll do it with the boolean-field
     // except you can use the CAST-function:
     // UPDATE test_pages SET parent_id_temp = CAST(parent_id AS integer)
     $installer->execute('ALTER TABLE test_pages ALTER COLUMN parent_id TYPE integer');
     $installer->addColumn('test_pages', 'is_public_temp boolean');
     $installer->execute('UPDATE test_pages
          SET is_public_temp =
                  CASE is_public
                    WHEN 0 THEN false
                    WHEN 1 THEN true
                    ELSE NULL
                  END');
     $installer->removeColumn('test_pages', 'is_public');
     $installer->renameColumn('test_pages', 'is_public_temp', 'is_public');
     $installer->transactionComplete();
     // let's see what we got
     $from_datadict = $this->db->getColumnDetails('test_pages');
     $this->assertEqual($from_datadict['PARENT_ID']->type, 'int4');
     $this->assertEqual($from_datadict['IS_PUBLIC']->type, 'bool');
     $data = $this->db->select('SELECT * FROM test_pages');
     $expected = array(array('id' => 1, 'parent_id' => null, 'is_public' => 't'), array('id' => 2, 'parent_id' => null, 'is_public' => 'f'), array('id' => 3, 'parent_id' => 1, 'is_public' => null));
     $this->assertEqual($data, $expected);
     // ok, we're done
     $installer->dropTable('test_pages');
 }
Ejemplo n.º 6
0
 function drop($table_name)
 {
     $Installer = new AkInstaller();
     $Installer->dropTable($table_name);
     $this->assertFalse(self::table_exists($table_name));
 }
Ejemplo n.º 7
0
 public function test_should_remove_associated_using_the_right_key()
 {
     $Installer = new AkInstaller();
     @$Installer->dropTable('groups_users');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'group_user.php');
     $this->installAndIncludeModels('User', 'Group', array('instantiate' => true));
     $Admin =& $this->Group->create(array('name' => 'Admin'));
     $Moderator =& $this->Group->create(array('name' => 'Moderator'));
     $this->assertFalse($Admin->hasErrors());
     $this->assertFalse($Moderator->hasErrors());
     $Salavert =& $this->User->create(array('name' => 'Jose'));
     $this->assertFalse($Salavert->hasErrors());
     $Salavert->group->setByIds($Admin->getId(), $Moderator->getId());
     $Salavert =& $this->User->find($Salavert->getId());
     $this->assertEqual(2, $Salavert->group->count());
     $Jyrki =& $this->User->create(array('name' => 'Jyrki'));
     $this->assertFalse($Jyrki->hasErrors());
     $Jyrki->group->setByIds($Admin->getId(), $Moderator->getId());
     $Jyrki =& $this->User->find($Jyrki->getId());
     $this->assertEqual(2, $Jyrki->group->count());
     $Jyrki->destroy();
     $Salavert =& $this->User->find($Salavert->getId());
     $this->assertEqual(2, $Salavert->group->count());
 }
Ejemplo n.º 8
0
<?php

define('AK_SESSION_HANDLER', 1);
if (isset($_GET['expire'])) {
    define('AK_SESSION_EXPIRE', (int) $_GET['expire']);
}
require_once dirname(__FILE__) . '/../config.php';
Ak::db();
if (!empty($_GET['construct'])) {
    @AkDbSession::install();
    @AkAdodbCache::install();
} elseif (!empty($_GET['destruct'])) {
    AkAdodbCache::uninstall();
    AkDbSession::uninstall();
    $Installer = new AkInstaller();
    $Installer->dropTable('akelos_migrations');
}
$session_handler = isset($_GET['handler']) ? $_GET['handler'] : null;
$session_settings = Ak::getSettings('sessions', false);
if ($session_handler !== null) {
    $session_settings['handler']['type'] = (int) $session_handler;
}
error_reporting(E_STRICT);
$SessionHandler = AkSession::lookupStore($session_settings);
session_start();
if (isset($_GET['key']) && isset($_GET['value'])) {
    $_SESSION[$_GET['key']] = $_GET['value'];
} elseif (isset($_GET['key'])) {
    if (isset($_SESSION[$_GET['key']])) {
        echo $_SESSION[$_GET['key']];
    } else {
Ejemplo n.º 9
0
 public function dropTables($tables = array())
 {
     $installer = new AkInstaller();
     if (is_string($tables) && $tables == 'all') {
         $tables = Ak::db()->getAvailableTables();
     }
     foreach ($tables as $table) {
         $installer->dropTable($table, array('sequence' => true));
     }
 }
Ejemplo n.º 10
0
 static function uninstall()
 {
     $db = Ak::db();
     if ($db->tableExists('sessions')) {
         $Installer = new AkInstaller($db);
         $Installer->dropTable('sessions');
     }
 }