コード例 #1
0
 /**
  * Returns YUI3 configuration extension for custom option modules
  * @param array $args Not used
  * @return string JS code declaring YUI3 modules
  */
 public static function modules($args)
 {
     $importINI = eZINI::instance('sqliimport.ini');
     $modules = $importINI->variable('OptionsGUISettings', 'YUI3Modules');
     if (count($modules)) {
         $js = 'YUI3_config = YUI3_config || { modules: {}}' . chr(10);
         $tpl = SQLIImportUtils::templateInit();
         foreach ($modules as $name => $path) {
             $path = eZURLOperator::eZDesign($tpl, $path, 'ezdesign');
             $js .= 'YUI3_config.modules.' . $name . ' = { fullpath: "' . $path . '" };' . chr(10);
         }
         return $js;
     }
     return '';
 }
コード例 #2
0
 /**
  * Checks if current user has access to import item management (edit, remove...)
  * @return bool
  */
 public function userHasAccess()
 {
     // Check if user has access to handler alteration
     $aLimitation = array('SQLIImport_Type' => $this->attribute('handler'));
     $userHasAccess = SQLIImportUtils::hasAccessToLimitation('sqliimport', 'manageimports', $aLimitation);
     return $userHasAccess;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
    // 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');
}
コード例 #5
0
ファイル: addscheduled.php プロジェクト: heliopsis/SQLIImport
$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');
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
<?php

/* @type $cli eZCli */
/* @type $script eZScript */

// attach listeners for ezpEvents
ezpEvent::getInstance()->registerEventListeners();

// Clear view cache
SQLIImportUtils::viewCacheClear();

// Indexing will be trigerred by indexcontent cronjob

$cli->output( 'Cleanup is over :)' );

$memoryMax = memory_get_peak_usage(); // Result is in bytes
$memoryMax = round( $memoryMax / 1024 / 1024, 2 ); // Convert in Megabytes
$cli->output( 'Peak memory usage : '.$memoryMax.'M' );
コード例 #8
0
ファイル: list.php プロジェクト: nicolasaguenot/sqliimport
 * @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');
コード例 #9
0
ファイル: addimport.php プロジェクト: heliopsis/SQLIImport
    }
    $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');
コード例 #10
0
 /**
  * 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;
 }