function test_executeTasksTablesAlter()
 {
     $this->assertTrue($this->initDatabase(325, array('campaigns')) . 'failed to created version 325 of campaigns table');
     $tblCampaigns = $this->oDbh->quoteIdentifier($this->prefix . 'campaigns', true);
     // Insert some data to test the upgrade from... we know the schema being used so we can directly insert
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (1,'campaign one',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'h', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (2,'campaign two',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'm', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (3,'campaign three', 1, -1, -1, -1, '2000-01-01', '2000-01-01', 't', 'l', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (4,'campaign four',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'h', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (5,'campaign five',   1, 100, 10, 1, '2000-01-01', '2000-01-01', 't', 'm', 1, 1, 'f', 'f')");
     $this->oDbh->exec("INSERT INTO {$tblCampaigns} VALUES (6,'campaign six',   1, -1, -1, -1, '2000-01-01', '2000-01-01', 't', 'l', 1, 1, 'f', 'f')");
     Mock::generatePartial('OA_DB_UpgradeAuditor', $mockAuditor = 'OA_DB_UpgradeAuditor' . rand(), array('logAuditAction', 'setKeyParams'));
     $oLogger = new OA_UpgradeLogger();
     $oLogger->setLogFile('DB_Upgrade.test.log');
     $oDB_Upgrade = new OA_DB_Upgrade($oLogger);
     $oDB_Upgrade->oAuditor = new $mockAuditor($this);
     $oDB_Upgrade->oAuditor->setReturnValue('logAuditAction', true);
     $oDB_Upgrade->oAuditor->setReturnValue('setKeyParams', true);
     $oDB_Upgrade->init('constructive', 'tables_core', 326);
     $aDef325 = $this->oaTable->aDefinition;
     $oDB_Upgrade->aDBTables = $oDB_Upgrade->_listTables();
     $this->assertTrue($oDB_Upgrade->_verifyTasksTablesAlter(), 'failed _verifyTasksTablesAlter: change field');
     $this->assertTrue($oDB_Upgrade->_executeTasksTablesAlter(), 'failed _executeTasksTablesAlter: change field');
     $aDefDB = $oDB_Upgrade->oSchema->getDefinitionFromDatabase(array($this->prefix . 'campaigns'));
     $aDiff = $oDB_Upgrade->oSchema->compareDefinitions($this->aDefNew, $aDefDb);
     $this->assertEqual(count($aDiff), 0, 'comparison failed');
     $aResults = $this->oDbh->queryAll("SELECT * FROM " . $tblCampaigns);
     $this->assertIsa($aResults, 'array');
     $expected = array(1 => '5', 2 => '3', 3 => '0', 4 => '5', 5 => '3', 6 => '0');
     foreach ($aResults as $idx => $aRow) {
         $this->assertEqual($aRow['priority'], $expected[$aRow['campaignid']], ' unexpected campaign priority value detected after upgrade');
     }
 }
Ejemplo n.º 2
0
 /**
  * execute an upgrade package and audit
  *
  *
  * @return boolean
  */
 function upgradeExecute($input_file = '')
 {
     $this->oLogger->setLogFile($this->_getUpgradeLogFileName());
     $this->oDBUpgrader->logFile = $this->oLogger->logFile;
     $this->oConfiguration->clearConfigBackupName();
     if ($input_file) {
         $input_file = $this->upgradePath . $input_file;
     }
     if (!$this->_parseUpgradePackageFile($input_file)) {
         return false;
     }
     $this->oAuditor->setUpgradeActionId();
     // links the upgrade_action record with database_action records
     $this->oAuditor->setKeyParams(array('upgrade_name' => $this->package_file, 'version_to' => $this->aPackage['versionTo'], 'version_from' => $this->aPackage['versionFrom'], 'logfile' => basename($this->oLogger->logFile)));
     // do this here in case there is a fatal error
     // in one of the upgrade methods
     // this ensures that there is recovery info available after
     $this->oAuditor->logAuditAction(array('description' => 'FAILED', 'action' => UPGRADE_ACTION_UPGRADE_FAILED));
     $this->_writeRecoveryFile();
     if (!$this->runScript($this->aPackage['prescript'])) {
         $this->oLogger->logError('Failure in upgrade prescript ' . $this->aPackage['prescript']);
         return false;
     }
     if (!$this->upgradeSchemas()) {
         $this->oLogger->logError('Failure while upgrading schemas');
         return false;
     }
     if (!$this->runScript($this->aPackage['postscript'])) {
         $this->oLogger->logError('Failure in upgrade postscript ' . $this->aPackage['postscript']);
         return false;
     }
     if (!$this->oVersioner->putApplicationVersion($this->aPackage['versionTo'], $this->aPackage['product'])) {
         $this->oLogger->logError('Failed to update ' . $this->aPackage['product'] . ' version to ' . $this->aPackage['versionTo']);
         $this->message = 'Failed to update ' . $this->aPackage['product'] . ' version to ' . $this->aPackage['versionTo'];
         return false;
     }
     $this->versionInitialApplication = $this->aPackage['versionTo'];
     $this->oAuditor->updateAuditAction(array('description' => 'UPGRADE_COMPLETE', 'action' => UPGRADE_ACTION_UPGRADE_SUCCEEDED, 'confbackup' => $this->oConfiguration->getConfigBackupName()));
     return true;
 }