/** * 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; } } }
/** * Initializes an object from RemoteID. * If no content object can be found, returns null * @param int $remoteID * @return SQLIContent|null */ public static function fromRemoteID($remoteID) { $contentObject = eZContentObject::fetchByRemoteID($remoteID); $content = null; if ($contentObject instanceof eZContentObject) { $content = self::fromContentObject($contentObject); } else { SQLIImportLogger::logWarning("Unable to find an eZContentObject with RemoteID {$remoteID}", false); } return $content; }
// Check if user has access to handler alteration $aLimitation = array('SQLIImport_Type' => $import->attribute('handler')); $hasAccess = SQLIImportUtils::hasAccessToLimitation($Module->currentModule(), 'manageimports', $aLimitation); if (!$hasAccess) { return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } switch ($action) { case 'cancel': // Check if import is already running. Maybe user has not refreshed import list in the admin... $status = $import->attribute('status') == SQLIImportItem::STATUS_RUNNING ? SQLIImportItem::STATUS_INTERRUPTED : SQLIImportItem::STATUS_CANCELED; SQLIImportLogger::logNotice('User "' . $userLogin . '" (#' . $userID . ') requested cancelation of pending import #' . $importID . ' on ' . date('Y-m-d H:i'), false); $import->setAttribute('status', $status); $import->store(); break; case 'interrupt': SQLIImportLogger::logNotice('User "' . $userLogin . '" (#' . $userID . ') requested interruption of running import #' . $importID . ' on ' . date('Y-m-d H:i'), false); $import->setAttribute('status', SQLIImportItem::STATUS_INTERRUPTED); $import->store(); break; default: throw new SQLIImportBaseException(SQLIImportUtils::translate('extension/sqliimport/error', "Unknown alter import action '%action'", null, array('%action' => $action))); } $Module->redirectToView('list'); } catch (Exception $e) { $errMsg = $e->getMessage(); SQLIImportLogger::writeError($errMsg); $tpl->setVariable('error_message', $errMsg); $Result['path'] = array(array('url' => false, 'text' => SQLIImportUtils::translate('extension/sqliimport/error', 'Error'))); $Result['left_menu'] = 'design:sqliimport/parts/leftmenu.tpl'; $Result['content'] = $tpl->fetch('design:sqliimport/altererror.tpl'); }
/** * Displays a message on the appropriate output (cli or eZDebug) * * @param string $msg * @param string $logType */ public static function writeMessage($msg, $logType = self::NOTICELOG) { self::$cli = eZCLI::instance(); $isWebOutput = self::$cli->isWebOutput(); switch ($logType) { case self::ERRORLOG: if (!$isWebOutput) { self::$cli->output(self::$cli->stylize('error', $msg)); } else { eZDebug::writeError($msg, 'SQLIImport'); } break; case self::WARNINGLOG: if (!$isWebOutput) { self::$cli->output(self::$cli->stylize('warning', $msg)); } else { eZDebug::writeWarning($msg, 'SQLIImport'); } break; case self::NOTICELOG: default: if (!$isWebOutput) { self::$cli->output(self::$cli->stylize('notice', $msg)); } else { eZDebug::writeNotice($msg, 'SQLIImport'); } break; } }
/** * Cleans up import process */ public function cleanup() { SQLIImportLogger::writeNotice('Now cleaning the import process'); $this->token = null; SQLIImportToken::cleanAll(); $this->restorePerformanceSettings(); // Update scheduled imports if (is_array($this->scheduledImports)) { foreach ($this->scheduledImports as $scheduledImport) { if (!$scheduledImport instanceof SQLIScheduledImport) { SQLIImportLogger::logError(__METHOD__ . '$scheduledImport is not an instance of SQLIScheduledImport !'); continue; } $scheduledImport->updateNextImport(); } } unset($this->scheduledImports); }