* @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2 * @author Jerome Vieilledent * @version @@@VERSION@@@ * @package sqliimport */ $Module = $Params['Module']; $Result = array(); $tpl = SQLIImportUtils::templateInit(); try { $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $userLogin = $user->attribute('login'); $action = $Params['Action']; $importID = $Params['ImportID']; $import = SQLIImportItem::fetch($importID); if (!$import instanceof SQLIImportItem) { throw new SQLIImportBaseException(SQLIImportUtils::translate('extension/sqliimport/error', "No import item found with ID #%importID", null, array('%importID' => $importID))); } // 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);
/** * Return Sqli import item if any * @return SQLIImportItem */ public function getCurrentSQLiImportItem() { $items = SQLIImportItem::fetchList( 0, 1, array( 'status' => SQLIImportItem::STATUS_RUNNING ) ); if ( count( $items ) == 1 ) return $items[0]; else return false; }
* Process requested import handlers * An SQLIImportItem object will be created and stored in DB for each handler */ $requestedHandlers = $options['source-handlers'] ? $options['source-handlers'] : ''; $aRequestedHandlers = $requestedHandlers ? explode(',', $requestedHandlers) : $importINI->variable('ImportSettings', 'AvailableSourceHandlers'); $areValidHandlers = SQLIImportFactory::checkExistingHandlers($aRequestedHandlers); // An exception may be thrown if a handler is not defined in sqliimport.ini 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);
// ########## // #################################################### // ########## // ##### Scheduled imports // ########## // First fetch all scheduled imports to be processed $currentTimestamp = time(); $conds = array('is_active' => 1, 'next' => array('<=', $currentTimestamp)); $aScheduledImports = SQLIScheduledImport::fetchList(0, null, $conds); // Then create a pending SQLIImportItem for each scheduled import if (count($aScheduledImports) > 0) { $cli->output('Now handling scheduled imports'); $aImportItems = array(); foreach ($aScheduledImports as $scheduledImport) { // Create pending import $aImportItems[] = SQLIImportItem::fromScheduledImport($scheduledImport); } $importFactory = SQLIImportFactory::instance(); $importFactory->setScheduledImports($aScheduledImports); $importFactory->runImport($aImportItems); $importFactory->cleanup(); unset($aImportItems, $aScheduledImports); } // ########## // ##### End Scheduled imports // ########## $cli->output('Import is over :)'); $memoryMax = memory_get_peak_usage(); // Result is in bytes $memoryMax = round($memoryMax / 1024 / 1024, 2); // Convert in Megabytes
* @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2 * @author Jerome Vieilledent * @version @@@VERSION@@@ * @package sqliimport */ $Module = $Params['Module']; $Result = array(); $tpl = SQLIImportUtils::templateInit(); try { $offset = isset($Params['UserParameters']['offset']) ? (int) $Params['UserParameters']['offset'] : 0; // Offset for pagination $limit = eZPreferences::value('sqliimport_import_limit'); $limit = $limit ? $limit : 10; // Default limit is 10 $imports = SQLIImportItem::fetchList($offset, $limit); $importCount = SQLIImportItem::count(SQLIImportItem::definition()); $currentURI = '/' . $Module->currentModule() . '/' . $Module->currentView(); $tpl->setVariable('imports', $imports); $tpl->setVariable('offset', $offset); $tpl->setVariable('limit', $limit); $tpl->setVariable('uri', $currentURI); $tpl->setVariable('import_count', $importCount); $tpl->setVariable('view_parameters', $Params['UserParameters']); } 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', 'Import management list'))); $Result['left_menu'] = 'design:sqliimport/parts/leftmenu.tpl'; $Result['content'] = $tpl->fetch('design:sqliimport/list.tpl');
<?php /** * SQLi Import import purge history import view * @copyright Copyright (C) 2010 - SQLi Agency. All rights reserved * @licence http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2 * @author Jerome Vieilledent * @version @@@VERSION@@@ * @package sqliimport */ $Module = $Params['Module']; $Result = array(); $tpl = SQLIImportUtils::templateInit(); try { $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $userLogin = $user->attribute('login'); SQLIImportLogger::logNotice('User "' . $userLogin . '" (#' . $userID . ') requested import history purge on ' . date('Y-m-d H:i'), false); SQLIImportItem::purgeImportHistory(); $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'); }
$Result = array(); $tpl = SQLIImportUtils::templateInit(); $importINI = eZINI::instance('sqliimport.ini'); $http = eZHTTPTool::instance(); try { $userLimitations = SQLIImportUtils::getSimplifiedUserAccess('sqliimport', 'manageimports'); $simplifiedLimitations = $userLimitations['simplifiedLimitations']; if ($Module->isCurrentAction('RequestImport')) { // Check if user has access to handler alteration $aLimitation = array('SQLIImport_Type' => $Module->actionParameter('ImportHandler')); $hasAccess = SQLIImportUtils::hasAccessToLimitation($Module->currentModule(), 'manageimports', $aLimitation); if (!$hasAccess) { return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } $importOptions = $Module->actionParameter('ImportOptions'); $pendingImport = new SQLIImportItem(array('handler' => $Module->actionParameter('ImportHandler'), 'user_id' => eZUser::currentUserID())); if ($importOptions) { if (is_array($importOptions)) { $pendingImport->setAttribute('options', SQLIImportHandlerOptions::fromHTTPInput($importOptions)); } else { //backwards compatibility mode : options are set in a textarea $pendingImport->setAttribute('options', SQLIImportHandlerOptions::fromText($importOptions)); } } $pendingImport->store(); $Module->redirectToView('list'); } $importHandlers = $importINI->variable('ImportSettings', 'AvailableSourceHandlers'); $aValidHandlers = array(); // Check if import handlers are enabled foreach ($importHandlers as $handler) {