/**
 * Cleanup handler, in case of a non caught DB transaction error
 * @return void
 */
function SQLIImportCleanupHandler()
{
    // Check if an error has occurred and report it if necessary
    $db = eZDB::instance();
    if ($db->errorNumber() > 0) {
        SQLIImportToken::cleanAll();
        $factory = SQLIImportFactory::instance();
        $currentItem = $factory->getCurrentImportItem();
        $currentItem->setAttribute('status', SQLIImportItem::STATUS_FAILED);
        $currentItem->store();
        SQLIImportLogger::logError('A DB transaction error occurred : #' . $db->errorNumber() . ' - "' . $db->errorMessage() . '"');
        SQLIImportLogger::logError('An error has occurred during import process. The import status has been updated.');
    }
}
 function sigHandler($signo)
 {
     if (SQLIImportToken::importIsRunning()) {
         // Note : SIGKILL cannot be caught
         // So try to always send a SIGINT (kill -2) or SIGTERM (kill -15) to request interruption
         switch ($signo) {
             case SIGTERM:
             case SIGINT:
                 SQLIImportLogger::logNotice('Caught SIGTERM while importing. Demanding import interruption (might take a little while)');
                 $factory = SQLIImportFactory::instance();
                 $currentItem = $factory->getCurrentImportItem();
                 $currentItem->setAttribute('status', SQLIImportItem::STATUS_INTERRUPTED);
                 $currentItem->store();
                 break;
         }
     }
 }
Esempio n. 3
0
        if ($aRequestedHandlers) {
            $aHandlersOptions = SQLIImportHandlerOptions::decodeHandlerOptionLine($options['options']);
            $importUser = eZUser::fetchByName('admin');
            // As this is a manual script, "Admin" user will be used to import
            $aImportItems = array();
            // First stores an SQLIImportItem for each handler to process
            foreach ($aRequestedHandlers as $handler) {
                $handlerOptions = isset($aHandlersOptions[$handler]) ? $aHandlersOptions[$handler] : null;
                $pendingImport = new SQLIImportItem(array('handler' => $handler, 'user_id' => $importUser->attribute('contentobject_id')));
                if ($handlerOptions instanceof SQLIImportHandlerOptions) {
                    $pendingImport->setAttribute('options', $handlerOptions);
                }
                $pendingImport->store();
                $aImportItems[] = $pendingImport;
            }
            $importFactory = SQLIImportFactory::instance();
            $importFactory->runImport($aImportItems);
            $importFactory->cleanup();
            $cli->notice('Import is over :)');
        } else {
            $cli->warning('No import handler to process ! Check sqliimport.ini to define handlers');
        }
        $memoryMax = memory_get_peak_usage();
        $memoryMax = round($memoryMax / 1024 / 1024, 2);
        // Convert in Megabytes
        $cli->notice('Peak memory usage : ' . $memoryMax . 'M');
    }
    $script->shutdown();
} catch (Exception $e) {
    $errCode = $e->getCode();
    $errCode = $errCode != 0 ? $errCode : 1;
Esempio n. 4
0
 /**
  * Singleton
  * @return SQLIImportFactory
  */
 public static function instance()
 {
     if (!self::$_instance instanceof SQLIImportFactory) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }