/** * Returns options form and js modules list for handler * @param array $args First value: handler id, optional second value: scheduled import id * @throws SQLIImportRuntimeException * @return array */ public static function options($args) { $scheduledImport = null; $currentOptions = null; $handler = $args[0]; //arg 2 may be a scheduled import id if (count($args) > 1) { $scheduledImport = SQLIScheduledImport::fetch($args[1]); if (!$scheduledImport) { throw new SQLIImportRuntimeException('Invalid scheduled import ID ' . $args[1]); } $currentOptions = $scheduledImport->attribute('options'); } $tpl = SQLIImportUtils::templateInit(); $importINI = eZINI::instance('sqliimport.ini'); $handlerSection = $handler . '-HandlerSettings'; if (!$importINI->hasSection($handlerSection)) { throw new SQLIImportRuntimeException('No config for handler ' . $handler); } if ($importINI->hasVariable($handlerSection, 'Options')) { $aHandlerOptions = array(); $optionsList = $importINI->variable($handlerSection, 'Options'); $optionsLabels = $importINI->variable($handlerSection, 'OptionsLabels'); $optionsTypes = $importINI->variable($handlerSection, 'OptionsTypes'); $optionsDefaults = $importINI->variable($handlerSection, 'OptionsDefaults'); foreach ($optionsList as $optionAlias) { $value = ''; if ($currentOptions && isset($currentOptions->{$optionAlias})) { $value = $currentOptions->{$optionAlias}; } elseif (isset($optionsDefaults[$optionAlias])) { $value = $optionsDefaults[$optionAlias]; } $aHandlerOptions[$optionAlias] = array('label' => isset($optionsLabels[$optionAlias]) ? $optionsLabels[$optionAlias] : $optionAlias, 'type' => isset($optionsTypes[$optionAlias]) ? $optionsTypes[$optionAlias] : 'string', 'value' => $value); } $tpl->setVariable('handler', $handler); $tpl->setVariable('handlerOptions', $aHandlerOptions); $tpl->setVariable('jsModules', array()); return array('form' => $tpl->fetch('design:sqliimport/parts/options.tpl'), 'modules' => $tpl->variable('jsModules')); } return ''; }
/** * Returns related scheduled import if it exists, or null if not * @return SQLIScheduledImport */ public function getScheduledImport() { $scheduledImport = null; if ($this->attribute('scheduled_id')) { $scheduledImport = SQLIScheduledImport::fetch($this->attribute('scheduled_id')); } return $scheduledImport; }
} else { $scheduledImport->fromArray($row); } if ($importOptions) { if (is_array($importOptions)) { $scheduledImport->setAttribute('options', SQLIImportHandlerOptions::fromHTTPInput($importOptions)); } else { //backwards compatibility mode : options are set in a textarea $scheduledImport->setAttribute('options', SQLIImportHandlerOptions::fromText($importOptions)); } } $scheduledImport->store(); $Module->redirectToView('scheduledlist'); } else { if ($Params['ScheduledImportID']) { $scheduledImport = SQLIScheduledImport::fetch($Params['ScheduledImportID']); $importID = $Params['ScheduledImportID']; $currentImportHandler = $scheduledImport->attribute('handler'); // Check if user has access to handler alteration $aLimitation = array('SQLIImport_Type' => $currentImportHandler); $hasAccess = SQLIImportUtils::hasAccessToLimitation($Module->currentModule(), 'manageimports', $aLimitation); if (!$hasAccess) { return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } $importOptions = $scheduledImport->attribute('options')->toText(); $nextTime = $scheduledImport->attribute('next'); if (!$nextTime) { $nextTime = $scheduledImport->attribute('requested_time'); } $importDate = date('Y-m-d', $nextTime); $importHour = date('H', $nextTime);
* @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(); $db = eZDB::instance(); try { $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $userLogin = $user->attribute('login'); $importID = $Params['ImportID']; $db->begin(); $import = SQLIScheduledImport::fetch($importID); if (!$import instanceof SQLIScheduledImport) { 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) { SQLIImportLogger::logNotice('User "' . $userLogin . '" (#' . $userID . ') removed scheduled import #' . $importID . ' on ' . date('Y-m-d H:i'), false); $import->remove(); $db->commit(); $Module->redirectToView('scheduledlist'); } else { $db->rollback(); return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); }