public function testDiff()
 {
     $sql = "\nCREATE TABLE `album`\n(\n    `id` INTEGER  NOT NULL AUTO_INCREMENT,\n    `id_artist` INTEGER default 0 NOT NULL,\n    `name` VARCHAR(255) default '',\n    `type` VARCHAR(16) default 'empty' NOT NULL,\n    PRIMARY KEY (`id`),\n    KEY `id_artist`(`id_artist`),\n    CONSTRAINT `album_FK_1`\n        FOREIGN KEY (`id_artist`)\n        REFERENCES `artist` (`id`)\n        ON UPDATE CASCADE\n        ON DELETE CASCADE\n)Type=innoDB;\n      ";
     $i = new dbInfo();
     $i->getTableInfoFromCreate($sql);
     $this->assertEqual($i->getDiffWith($i), '');
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $buildSql = new sfPropelBuildSqlTask($this->dispatcher, $this->formatter);
     $buildSql->setCommandApplication($this->commandApplication);
     $buildSql->run();
     $this->logSection("sql-diff", "building database patch");
     $i = new dbInfo();
     $i->loadFromDb(Propel::getConnection($options['connection']));
     $i2 = new dbInfo();
     $sqlDir = sfConfig::get('sf_data_dir') . '/sql';
     $dbmap = file("{$sqlDir}/sqldb.map");
     foreach ($dbmap as $mapline) {
         if ($mapline[0] == '#') {
             continue;
         }
         //it is a comment
         list($sqlfile, $dbname) = explode('=', trim($mapline));
         if ($dbname == $options['connection']) {
             $i2->loadFromFile("{$sqlDir}/{$sqlfile}");
         }
     }
     $diff = $i->getDiffWith($i2);
     $filename = sfConfig::get('sf_data_dir') . "/sql/{$options['connection']}.diff.sql";
     if ($diff == '') {
         $this->logSection("sql-diff", "no difference found");
     }
     $this->logSection('sql-diff', "writing file {$filename}");
     file_put_contents($filename, $diff);
 }
Exemplo n.º 3
0
function run_propel_insert_sql_diff($task, $args)
{
    run_propel_build_sql_diff($task, $args);
    $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
    pake_echo_action('propel-sql-diff', "executing file {$filename}");
    $i = new dbInfo();
    $i->executeSql(file_get_contents($filename));
}
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $buildSql = new sfPropelBuildSqlDiffTask($this->dispatcher, $this->formatter);
     $buildSql->setCommandApplication($this->commandApplication);
     $buildSql->execute($arguments, $options);
     $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
     $this->logSection("propel-diff", "executing file {$filename}");
     $i = new dbInfo();
     $i->executeSql(file_get_contents($filename));
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $buildSql = new sfPropelBuildSqlTask($this->dispatcher, $this->formatter);
     $buildSql->setCommandApplication($this->commandApplication);
     $buildSql->run();
     $this->logSection("propel-diff", "building database patch");
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $i = new dbInfo();
     $i->loadFromDb();
     $i2 = new dbInfo();
     $i2->loadAllFilesInDir(sfConfig::get('sf_data_dir') . '/sql');
     $diff = $i->getDiffWith($i2);
     $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
     if ($diff == '') {
         $this->logSection("propel-diff", "no difference found");
     }
     $this->logSection('propel-sql-diff', "writing file {$filename}");
     file_put_contents($filename, $diff);
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $optionsCmdline = array();
     if ($options['application']) {
         $optionsCmdline[] = '--application=' . $options['application'];
     }
     if ($options['env']) {
         $optionsCmdline[] = '--env=' . $options['env'];
     }
     if ($options['connection']) {
         $optionsCmdline[] = '--connection=' . $options['connection'];
     }
     $buildSql = new sfPropelBuildSqlDiffTask($this->dispatcher, $this->formatter);
     $buildSql->setCommandApplication($this->commandApplication);
     $buildSql->run(array(), $optionsCmdline);
     $filename = sfConfig::get('sf_data_dir') . "/sql/{$options['connection']}.diff.sql";
     $this->logSection("sql-diff", "executing file {$filename}");
     $i = new dbInfo();
     $i->executeSql(file_get_contents($filename), Propel::getConnection($options['connection']));
 }
Exemplo n.º 7
0
<?php

require_once dirname(__FILE__) . '/includes/system/config.php';
// classes
$dbInfo = new dbInfo();
$dbInfo->setHost('localhost');
$dbInfo->setUser('www-data');
$dbInfo->setPass('W3Wd@ta');
$dbInfo->setName('message');
$dm = new dm(false);
$dm->connectDb($dbInfo);
$dm->setVars('Message From Heaven', 'http://stoddart.message/', '/usr/local/www/data/message/');
$session = $dm->session();
$dm->setPaypalUser('sdk-three_api1.sdk.com');
// test = sdk-three_api1.sdk.com, live = ic3000_api1.q.com
$dm->setPaypalPwd('QFZCWN5HZM8VBG7Q');
// test = QFZCWN5HZM8VBG7Q, live = HM9HWZ6C8MGM5JPR
$dm->setPaypalSignature('A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU');
// test = A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU, live = Afzwki5kM8uclaP2ELeT59viD7-cAiKF71gyXndwl5alQmTaz-q5geM9
$dm->setPaypalMode('test');
// 'test' or 'live'
Exemplo n.º 8
0
 function getDiffWith(dbInfo $db_info2)
 {
     $diff_sql = '';
     foreach ($db_info2->tables as $tablename => $tabledata) {
         if (!isset($this->tables[$tablename])) {
             $diff_sql .= "\n" . $db_info2->tables[$tablename]['create'] . "\n";
             continue;
         }
         foreach ($tabledata['fields'] as $field => $fielddata) {
             $mycode = $fielddata['code'];
             $othercode = @$this->tables[$tablename]['fields'][$field]['code'];
             if ($mycode and !$othercode) {
                 $diff_sql .= "ALTER TABLE `{$tablename}` ADD `{$field}` {$mycode};\n";
             }
         }
         if ($tabledata['keys']) {
             foreach ($tabledata['keys'] as $field => $fielddata) {
                 $mycode = $fielddata['code'];
                 $otherdata = @$this->tables[$tablename]['keys'][$field];
                 $othercode = @$otherdata['code'];
                 if ($mycode and !$othercode) {
                     if ($otherdata['type'] == 'PRIMARY') {
                         $diff_sql .= "ALTER TABLE `{$tablename}` ADD PRIMARY KEY {$mycode};\n";
                     } else {
                         $diff_sql .= "ALTER TABLE `{$tablename}` ADD {$fielddata['type']} INDEX `{$field}` {$mycode};\n";
                     }
                 }
             }
         }
         if ($tabledata['fkeys']) {
             foreach ($tabledata['fkeys'] as $fkeyname => $data) {
                 $mycode = $data['code'];
                 $otherfkname = $this->get_fk_name_by_field($tablename, $data['field']);
                 $otherdata = @$this->tables[$tablename]['fkeys'][$otherfkname];
                 if ($data['ref_table'] != $otherdata['ref_table'] or $data['ref_field'] != $otherdata['ref_field'] or $data['on_delete'] != $otherdata['on_delete'] or $data['on_update'] != $otherdata['on_update']) {
                     $diff_sql .= "ALTER TABLE `{$tablename}` ADD {$mycode};\n";
                 }
             }
         }
     }
     foreach ($this->tables as $tablename => $tabledata) {
         if (!isset($db_info2->tables[$tablename])) {
             $diff_sql .= "DROP TABLE `{$tablename}`;\n";
             continue;
         }
         //drop, alter foreign key
         if ($tabledata['fkeys']) {
             foreach ($tabledata['fkeys'] as $fkeyname => $data) {
                 $mycode = $data['code'];
                 $otherfkname = $db_info2->get_fk_name_by_field($tablename, $data['field']);
                 $othercode = @$db_info2->tables[$tablename]['fkeys'][$otherfkname]['code'];
                 if ($mycode and !$othercode) {
                     $diff_sql .= "ALTER TABLE `{$tablename}` DROP FOREIGN KEY `{$fkeyname}`;\n";
                 } else {
                     $data2 = $db_info2->tables[$tablename]['fkeys'][$otherfkname];
                     if ($data['ref_table'] != $data2['ref_table'] || $data['ref_field'] != $data2['ref_field'] || $data['on_delete'] != $data2['on_delete'] || $data['on_update'] != $data2['on_update']) {
                         if ($this->debug) {
                             $diff_sql .= "/* old definition: {$mycode}\n   new definition: {$othercode} */\n";
                         }
                         $diff_sql .= "ALTER TABLE `{$tablename}` DROP FOREIGN KEY `{$fkeyname}`;\n";
                         $diff_sql .= "ALTER TABLE `{$tablename}` ADD {$othercode};\n";
                     }
                 }
             }
         }
         //drop, alter index
         if ($tabledata['keys']) {
             foreach ($tabledata['keys'] as $field => $fielddata) {
                 $otherdata = @$db_info2->tables[$tablename]['keys'][$field];
                 $ind_name = @$otherdata['type'] == 'PRIMARY' ? 'PRIMARY KEY' : "{$otherdata['type']} INDEX";
                 if ($fielddata['code'] and !$otherdata['code']) {
                     if ($fielddata['type'] == 'PRIMARY') {
                         $diff_sql .= "ALTER TABLE `{$tablename}` DROP PRIMARY KEY;\n";
                     } else {
                         $diff_sql .= "ALTER TABLE `{$tablename}` DROP INDEX {$field};\n";
                     }
                 } elseif ($fielddata['fields'] != $otherdata['fields'] or $fielddata['type'] != $otherdata['type']) {
                     if ($this->debug) {
                         $diff_sql .= "/* old definition: {$fielddata['code']}\n   new definition: {$otherdata['code']} */\n";
                     }
                     if ($fielddata['type'] == 'PRIMARY') {
                         $diff_sql .= "ALTER TABLE `{$tablename}` DROP PRIMARY KEY,";
                     } else {
                         $diff_sql .= "ALTER TABLE `{$tablename}` DROP INDEX {$field},";
                     }
                     $diff_sql .= "        ADD {$ind_name} " . ($field ? "`{$field}`" : "") . " {$otherdata['code']};\n";
                 }
             }
         }
         //drop, alter field
         foreach ($tabledata['fields'] as $field => $fielddata) {
             $mycode = $fielddata['code'];
             $otherdata = @$db_info2->tables[$tablename]['fields'][$field];
             $othercode = @$otherdata['code'];
             if ($mycode and !$othercode) {
                 $diff_sql .= "ALTER TABLE `{$tablename}` DROP `{$field}`;\n";
             } elseif ($fielddata['type'] != $otherdata['type'] or $fielddata['type'] != $otherdata['type'] or $fielddata['null'] != $otherdata['null'] or $fielddata['default'] != $otherdata['default']) {
                 if ($this->debug) {
                     $diff_sql .= "/* old definition: {$mycode}\n   new definition: {$othercode} */\n";
                 }
                 $diff_sql .= "ALTER TABLE `{$tablename}` CHANGE `{$field}` `{$field}` {$othercode};\n";
             }
         }
     }
     return $diff_sql;
 }
Exemplo n.º 9
0
<?php

require_once dirname(__FILE__) . '/includes/system/config.php';
// classes
$dbInfo = new dbInfo();
$dbInfo->setHost('localhost');
$dbInfo->setUser('root');
$dbInfo->setPass('');
$dbInfo->setName('jcr_2007');
$dm = new dm(false);
$dm->connectDb($dbInfo);
$dm->setVars('2007 Rankings', 'http://vm.comp_rankings/2007/', '/home/jon/www/misc/comp_rankings/2007/');