Beispiel #1
0
 public function commitBatch($cleanup = false, $continueOnError = false)
 {
     $count = 0;
     if (sizeof(self::$_currentBatches) > 0) {
         foreach (self::$_currentBatches as $id => $batchFile) {
             if (preg_match('/' . $this->entity_name . '/', $id)) {
                 self::$_logger->debug('Looking for batch file ' . $batchFile);
                 if (is_file($batchFile)) {
                     //before executing batch, use command 'COMMIT'
                     $tempDir = dirname($batchFile) . '/';
                     $fileName = basename($batchFile);
                     CacheHelper::addToCache($tempDir, $fileName, "COMMIT;");
                     self::$_logger->debug('Processing batch file ' . $batchFile);
                     $dbUsername = $this->{FrameworkConstants::DATABASE_USERNAME};
                     $dbPassword = $this->{FrameworkConstants::DATABASE_PASSWORD};
                     $dbHost = $this->{FrameworkConstants::DATABASE_HOST};
                     $dbName = $this->{FrameworkConstants::DATABASE_NAME};
                     $mysqlCommand = $this->{FrameworkConstants::MYSQL_COMMAND};
                     if (empty($mysqlCommand)) {
                         throw new Exception('MYSQL command line parameter was not set in your env_db.ini for datasource ' . $this->{FrameworkConstants::DATABASE_CONFIG_SECTION});
                     }
                     if (!$continueOnError) {
                         $continueOnError = $this->{FrameworkConstants::MYSQL_COMMAND_CONTINUE_ON_ERROR};
                     }
                     if (!empty($continueOnError) || $continueOnError) {
                         $continueOnError = '--force';
                     }
                     $command = $mysqlCommand . ' ' . $continueOnError . ' --user='******' --password='******' --host=' . $dbHost . ' --database= ' . $dbName;
                     $command .= ' < ' . $batchFile;
                     exec($command, $output, $count);
                     self::$_logger->debug($output);
                     if ($cleanup) {
                         unlink($batchFile);
                     }
                 }
             }
         }
     }
 }