function setup()
 {
     if (!empty($this->data)) {
         $data = $this->data;
         $install_files_path = CONFIGS . 'install' . DS;
         $connection = array();
         foreach (array('driver', 'host', 'login', 'password', 'database', 'prefix') as $k) {
             $connection[$k] = $data[$k];
         }
         $this->_writeDBConfig($connection);
         uses('model' . DS . 'connection_manager');
         $db = ConnectionManager::getInstance();
         $connection = $db->getDataSource('default');
         if ($connection->isConnected()) {
             App::import('vendor', 'migrations');
             $oMigrations = new Migrations();
             $oMigrations->load($install_files_path . 'schema.yml');
             $dbRes = $oMigrations->up();
             if (is_array($dbRes)) {
                 $error_string = '';
                 foreach ($dbRes as $error) {
                     $error_string .= $error['error'] . '<br />';
                 }
                 $this->Session->setFlash(__('There were some errors during the creation of your db tables', true) . ':<br />' . $error_string);
             } elseif ($dbRes == true) {
                 //add admin to the users table
                 App::import('model', array('User', 'Site'));
                 $User = new User();
                 $User->save(array('username' => $data['admin_username'], 'password' => sha1(Configure::read('Security.salt') . $data['admin_password']), 'group_id' => 1));
                 /*$Site = new Site();
                   $Site->save( array( 'user_id' => $User->getInsertID(), 'domain' => Configure::read( 'CMS.Site.Domain' ) ) );*/
                 App::import('vendor', 'fixtures');
                 $oFixtures = new Fixtures();
                 if ($oFixtures->import($install_files_path . 'fixtures.yml') === true) {
                     $this->flash('Congratulations, you have successfully installed Pagebakery!', '/');
                 } else {
                     $this->Session->setFlash(__('Sorry, there was an error adding initial data', true));
                 }
             }
         } else {
             $this->Session->setFlash('I could not connect to the DataBase. Please check the setup details again.');
         }
     }
     $this->set('DBDrivers', $this->_getDBDrivers());
 }
Esempio n. 2
0
 public function testLoadLoadsPHPfiles()
 {
     $om = $this->getDoctrineManagerMock(1);
     $objects = Fixtures::load(__DIR__ . '/fixtures/basic.php', $om);
     $this->assertCount(1, $objects);
     $user = $objects[0];
     $this->assertInstanceOf(self::USER, $user);
     $this->assertEquals('johnny', $user->username);
     $this->assertEquals(42, $user->favoriteNumber);
 }
 /**
  * Main method: Imports all fixtures from the fixtures path
  */
 function main()
 {
     if (!class_exists('Spyc')) {
         $this->error('File not found', 'YAML class is needed for this shell to run. Could not be found - exiting.');
     }
     $oFolder = new Folder(FIXTURES_PATH);
     $aFixtures = $oFolder->find('.+_fixture\\.yml');
     $oFixtures = new Fixtures($this->sConnection);
     $iCount = 0;
     foreach ($aFixtures as $sFixture) {
         $iCount++;
         if ($oFixtures->import(FIXTURES_PATH . DS . $sFixture) !== true) {
             $this->error('Import failed.', 'Sorry, there was an error inserting the data into your database');
         } else {
             $this->out('Importing ' . $sFixture . '...');
             $this->out('');
         }
     }
     $this->out($iCount . ' fixture(s) successfully imported');
 }
Esempio n. 4
0
 static function get($args)
 {
     $key = Fixtures::getArgsKey($args);
     $cli_root = dirname(dirname(__DIR__));
     $filename = sprintf('%s/%s/%s', $cli_root, self::$fixtures_dir, $key);
     if (file_exists($filename)) {
         return unserialize(file_get_contents("{$filename}"));
     } else {
         var_dump($filename);
     }
     return false;
 }
Esempio n. 5
0
        $templateComment = '{"@class": "Comment", "body": "comment number %d" }';
        for ($i = 0; $i <= 5; $i++) {
            $this->client->post('/document/' . $this->dbname, $this->contentType, sprintf($templateComment, $i, $i))->send();
        }
        //Insert Post
        $templatePost = '{"@class": "Post", "id":%d,"title": "%d", "body": "Body %d", "comments":["#' . $this->Comment . ':3"] }';
        for ($i = 0; $i <= 5; $i++) {
            $this->client->post('/document/' . $this->dbname, $this->contentType, sprintf($templatePost, $i, $i, $i))->send();
        }
        $this->client->post('/document/' . $this->dbname, $this->contentType, '{"@class": "Post", "id":6,"title": "titolo 6", "body": "Body 6", "comments":["#' . $this->Comment . ':2"] }')->send();
        //Insert MapPoint
        $this->client->post('/document/' . $this->dbname, $this->contentType, '{"@class": "MapPoint", "x": "42.573968", "y": "13.203125" }')->send();
        $templatePerson = '{"@class": "PersonV", "name": "%s"}';
        foreach (['George', 'Cameron', 'Sydney'] as $name) {
            $this->client->post('/document/' . $this->dbname, $this->contentType, sprintf($templatePerson, $name))->send();
        }
        $templatePost = '{"@class": "PostV", "title": "%s"}';
        foreach (['Hello World', 'Welcome World', 'Another Post'] as $title) {
            $this->client->post('/document/' . $this->dbname, $this->contentType, sprintf($templatePost, $title))->send();
        }
        $likeE = 'CREATE EDGE LikedE FROM %s to %s';
        $this->client->post(sprintf('/command/%s/sql', $this->dbname), $this->contentType, sprintf($likeE, '#26:0', '#29:0'))->send();
        $followsE = 'CREATE EDGE FollowedE FROM %s to %s';
        $this->client->post(sprintf('/command/%s/sql', $this->dbname), $this->contentType, sprintf($followsE, '#26:0', '#26:1'))->send();
        $this->client->post(sprintf('/command/%s/sql', $this->dbname), $this->contentType, sprintf($followsE, '#26:2', '#26:1'))->send();
        $this->client->post(sprintf('/command/%s/sql', $this->dbname), $this->contentType, sprintf($followsE, '#26:1', '#26:0'))->send();
        return $this;
    }
}
$fixtures = new Fixtures('ODMTest', 'root', 'password');
$fixtures->clean()->create_classes()->load_fixtures();
Esempio n. 6
0
            $sql = "insert into admin (userName, password) VALUES (:userName, :password)";
            $sth = $dbh->prepare($sql);
            $sth->execute($data);
            $db = null;
        } catch (PDOException $e) {
            echo "I'm sorry, Dave. I'm afraid I can't do that.";
            file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
        }
    }
}
$team1 = array('name1' => 'Mirentxu', 'surname1' => 'Vera', 'phone1' => '986304040', 'email1' => '*****@*****.**', 'name2' => 'Maria Jose', 'surname2' => 'Moure', 'phone2' => '986304050', 'email2' => '*****@*****.**', 'userName' => 'veraMoure', 'password' => 'vera');
$team2 = array('name1' => 'Xandra', 'surname1' => 'Lopez', 'phone1' => '986304060', 'email1' => '*****@*****.**', 'name2' => 'Paola', 'surname2' => 'Strasser', 'phone2' => '986304070', 'email2' => '*****@*****.**', 'userName' => 'lopezStrasser', 'password' => 'lopez');
$team3 = array('name1' => 'Loreto', 'surname1' => 'Ramos', 'phone1' => '986304080', 'email1' => '*****@*****.**', 'name2' => 'Carla', 'surname2' => 'Barciela', 'phone2' => '986305010', 'email2' => '*****@*****.**', 'userName' => 'ramosBarciela', 'password' => 'ramos');
$admin = array('userName' => 'admin', 'password' => 'admin123');
$league1 = array('name' => 'League A', 'status' => 'Active', 'year' => '2010');
$league2 = array('name' => 'League C', 'status' => 'Active', 'year' => '2011');
$league3 = array('name' => 'League B', 'status' => 'Inactive', 'year' => '2009');
$fixtures = new Fixtures();
$fixtures->dropTableTeam();
$fixtures->createTableTeam();
$fixtures->insertTeam($team1);
$fixtures->insertTeam($team2);
$fixtures->insertTeam($team3);
$fixtures->dropTableAdmin();
$fixtures->createTableAdmin();
$fixtures->insertAdmin($admin);
$fixtures->dropTableLeague();
$fixtures->createTableLeague();
$fixtures->insertLeague($league1);
$fixtures->insertLeague($league2);
$fixtures->insertLeague($league3);
Esempio n. 7
0
class Fixtures
{
    public function insert(array $team)
    {
        require_once '../lib/database.php';
        try {
            extract($team);
            $data = array(':name1' => $name1, ':surname1' => $surname1, ':phone1' => $phone1, ':email1' => $email1, ':name2' => $name2, ':surname2' => $surname2, ':phone2' => $phone2, ':email2' => $email2, ':userName' => $userName, ':password' => sha1($password));
            echo '<pre>';
            print_r($data);
            $dbh = new Database();
            $sql = "insert into team (name1, surname1, phone1, email1, name2,\n                surname2, phone2, email2, userName, password) \n                VALUES (:name1, :surname1, :phone1, :email1, :name2, :surname2, \n                :phone2, :email2, :userName, :password)";
            //            $sql = "insert into team (name1) VALUES (:name1)";
            //            insert into team (name1) values ('test')
            $sth = $dbh->prepare($sql);
            $sth->execute($data);
            $db = null;
        } catch (PDOException $e) {
            echo "I'm sorry, Dave. I'm afraid I can't do that.";
            file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
        }
    }
}
$team1 = array('name1' => 'Mirentxu', 'surname1' => 'Vera', 'phone1' => '986304040', 'email1' => '*****@*****.**', 'name2' => 'Maria Jose', 'surname2' => 'Moure', 'phone2' => '986304050', 'email2' => '*****@*****.**', 'userName' => 'veraMoure', 'password' => 'vera');
$team2 = array('name1' => 'Xandra', 'surname1' => 'Lopez', 'phone1' => '986304060', 'email1' => '*****@*****.**', 'name2' => 'Paola', 'surname2' => 'Strasser', 'phone2' => '986304070', 'email2' => '*****@*****.**', 'userName' => 'lopezStrasser', 'password' => 'lopez');
$team3 = array('name1' => 'Loreto', 'surname1' => 'Ramos', 'phone1' => '986304080', 'email1' => '*****@*****.**', 'name2' => 'Carla', 'surname2' => 'Barciela', 'phone2' => '986305010', 'email2' => '*****@*****.**', 'userName' => 'ramosBarciela', 'password' => 'ramos');
$fixtures = new Fixtures();
$fixtures->insert($team1);
$fixtures->insert($team2);
$fixtures->insert($team3);