/** * Sets attributes directly from an associative array. * Key is the attribute name * @param array $attributes */ public function fromArray(array $attributes) { foreach ($attributes as $attrName => $attrValue) { if (isset($this->attributesHolder[$attrName])) { $this->attributesHolder[$name] = $value; } else { throw new SQLIImportRuntimeException(SQLIImportUtils::translate('extension/sqliimport/error', 'SQLIPendingImport : Unknown attribute "%attribute"', null, $name)); } } }
// 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'); }
/** * Returns "full" frequency * @return string */ public function getFullFrequency() { $freq = null; switch ($this->attribute('frequency')) { case self::FREQUENCY_MANUAL: $freq = $this->attribute('frequency') . ' (' . $this->attribute('manual_frequency') . ' ' . SQLIImportUtils::translate('extension/sqliimport', 'Minutes') . ')'; break; default: $freq = $this->attribute('frequency'); } return $freq; }
$tpl->setVariable('import_hour', $importHour); $tpl->setVariable('import_minute', $importMinute); $tpl->setVariable('import_frequency', $importFrequency); $tpl->setVariable('import_label', $importLabel); $tpl->setVariable('import_is_active', $importIsActive); $tpl->setVariable('manual_frequency', $manualFrequency); $importHandlers = $importINI->variable('ImportSettings', 'AvailableSourceHandlers'); $aValidHandlers = array(); // Check if import handlers are enabled foreach ($importHandlers as $handler) { $handlerSection = $handler . '-HandlerSettings'; if ($importINI->variable($handlerSection, 'Enabled') === 'true') { $handlerName = $importINI->hasVariable($handlerSection, 'Name') ? $importINI->variable($handlerSection, 'Name') : $handler; /* * Policy limitations check. * User has access to handler if it appears in $simplifiedLimitations['SQLIImport_Type'] * or if $simplifiedLimitations['SQLIImport_Type'] is not set (no limitations) */ if (isset($simplifiedLimitations['SQLIImport_Type']) && in_array($handler, $simplifiedLimitations['SQLIImport_Type']) || !isset($simplifiedLimitations['SQLIImport_Type'])) { $aValidHandlers[$handlerName] = $handler; } } } $tpl->setVariable('importHandlers', $aValidHandlers); //session vars used by file uploader $tpl->setVariable('session_id', session_id()); $tpl->setVariable('session_name', session_name()); $tpl->setVariable('user_session_hash', eZSession::getUserSessionHash()); $Result['path'] = array(array('url' => false, 'text' => SQLIImportUtils::translate('extension/sqliimport', 'Edit a scheduled import'))); $Result['left_menu'] = 'design:sqliimport/parts/leftmenu.tpl'; $Result['content'] = $tpl->fetch('design:sqliimport/addscheduled.tpl');
/** * publishHandlerLink (Publish handler, pass 2 after schema validation) * Publish handler for link element, converts href to [object|node|link]_id. * * @param DOMElement $element * @param array $params parameters for xml element * @return null|array changes structure if it contains 'result' key */ function publishHandlerLink($element, &$params) { $ret = null; $href = $element->getAttribute('href'); if ($href) { $objectID = false; if (strpos($href, 'ezobject') === 0 && preg_match("@^ezobject://([0-9]+)/?(#.+)?@i", $href, $matches)) { $objectID = $matches[1]; if (isset($matches[2])) { $anchorName = substr($matches[2], 1); } $element->setAttribute('object_id', $objectID); if (!eZContentObject::exists($objectID)) { $this->Messages[] = SQLIImportUtils::translate('design/standard/ezoe/handler', 'Object %1 does not exist.', false, array($objectID)); } } elseif (strpos($href, 'eznode') === 0 && preg_match("@^eznode://([^#]+)(#.+)?@i", $href, $matches)) { $nodePath = trim($matches[1], '/'); if (isset($matches[2])) { $anchorName = substr($matches[2], 1); } if (is_numeric($nodePath)) { $nodeID = $nodePath; $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node instanceof eZContentObjectTreeNode) { $this->Messages[] = SQLIImportUtils::translate('design/standard/ezoe/handler', 'Node %1 does not exist.', false, array($nodeID)); } } else { $node = eZContentObjectTreeNode::fetchByURLPath($nodePath); if (!$node instanceof eZContentObjectTreeNode) { $this->Messages[] = SQLIImportUtils::translate('design/standard/ezoe/handler', 'Node '%1' does not exist.', false, array($nodePath)); } else { $nodeID = $node->attribute('node_id'); } $element->setAttribute('show_path', 'true'); } if (isset($nodeID) && $nodeID) { $element->setAttribute('node_id', $nodeID); } if (isset($node) && $node instanceof eZContentObjectTreeNode) { $objectID = $node->attribute('contentobject_id'); } } elseif (strpos($href, '#') === 0) { $anchorName = substr($href, 1); } else { $temp = explode('#', $href); $url = $temp[0]; if (isset($temp[1])) { $anchorName = $temp[1]; } if ($url) { // Protection from XSS attack if (preg_match("/^(java|vb)script:.*/i", $url)) { $this->isInputValid = false; $this->Messages[] = "Using scripts in links is not allowed, '{$url}' has been removed"; $element->removeAttribute('href'); return $ret; } // Check mail address validity if (preg_match("/^mailto:([^\\?]*)(?:\\?.*)?/i", $url, $mailAddr)) { if (!eZMail::validate($mailAddr[1])) { $this->isInputValid = false; if ($this->errorLevel >= 0) { $this->Messages[] = SQLIImportUtils::translate('kernel/classes/datatypes/ezxmltext', "Invalid e-mail address: '%1'", false, array($mailAddr[1])); } $element->removeAttribute('href'); return $ret; } } // Store urlID instead of href $url = str_replace(array('&', '%28', '%29'), array('&', '(', ')'), $url); $urlID = eZURL::registerURL($url); if ($urlID) { if (!in_array($urlID, $this->urlIDArray)) { $this->urlIDArray[] = $urlID; } $element->setAttribute('url_id', $urlID); } } } if ($objectID && !in_array($objectID, $this->linkedObjectIDArray)) { $this->linkedObjectIDArray[] = $objectID; } if (isset($anchorName) && $anchorName) { $element->setAttribute('anchor_name', $anchorName); } } return $ret; }
* @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');
} $importHandlers = $importINI->variable('ImportSettings', 'AvailableSourceHandlers'); $aValidHandlers = array(); // Check if import handlers are enabled foreach ($importHandlers as $handler) { $handlerSection = $handler . '-HandlerSettings'; if ($importINI->variable($handlerSection, 'Enabled') === 'true') { $handlerName = $importINI->hasVariable($handlerSection, 'Name') ? $importINI->variable($handlerSection, 'Name') : $handler; /* * Policy limitations check. * User has access to handler if it appears in $simplifiedLimitations['SQLIImport_Type'] * or if $simplifiedLimitations['SQLIImport_Type'] is not set (no limitations) */ if (isset($simplifiedLimitations['SQLIImport_Type']) && in_array($handler, $simplifiedLimitations['SQLIImport_Type']) || !isset($simplifiedLimitations['SQLIImport_Type'])) { $aValidHandlers[$handlerName] = $handler; } } } $tpl->setVariable('importHandlers', $aValidHandlers); //session vars used by file uploader $tpl->setVariable('session_id', session_id()); $tpl->setVariable('session_name', session_name()); $tpl->setVariable('user_session_hash', eZSession::getUserSessionHash()); } 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', 'Request a new immediate import'))); $Result['left_menu'] = 'design:sqliimport/parts/leftmenu.tpl'; $Result['content'] = $tpl->fetch('design:sqliimport/addimport.tpl');
/** * Checks if file is in a valid format for $option * Returns true or throws an SQLIImportInvalidFileFormatException * * @param string $option File option alias * @param string $filePath File to validate. Must be a valid local file (fetched from cluster if needed) * @return boolean * @throws SQLIImportInvalidFileFormatException * @throws SQLIImportConfigException if $option is not right */ public function validateFile($option, $filePath) { if ($option !== 'file') { throw new SQLIImportConfigException('"' . $option . '" is not a valid file option. Correct value is "file"'); } $csvOptions = new SQLICSVOptions(array()); //extract headers in temp file to ensure fast csv parsing $f = fopen($filePath, 'r'); $headersLine = fgets($f, $csvOptions->csv_line_length); $headersLine .= fgets($f, $csvOptions->csv_line_length); fclose($f); $tmpFile = tempnam(sys_get_temp_dir(), 'usersimport'); file_put_contents($tmpFile, $headersLine); $csvOptions->csv_path = $tmpFile; $csv = new SQLICSVDoc($csvOptions); $csv->parse(); unlink($tmpFile); $requiredHeaders = array('login', 'password', 'email', 'firstName', 'lastName'); $sentHeaders = $csv->rows->getHeaders(); $diff = array_diff($requiredHeaders, $sentHeaders); if (!empty($diff)) { throw new SQLIImportInvalidFileFormatException(SQLIImportUtils::translate('sqliimport/usershandler', "File must contain the following columns: %required Sent columns are: %sent", '', array('%required' => implode($csvOptions->delimiter, $requiredHeaders), '%sent' => implode($csvOptions->delimiter, $sentHeaders)))); } return true; }