/**
  * 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;
     }
 }
function moveIfNeeded($oldPath, $newPath) {
    global $fileToRemove;
    
    $success = true;
    $cli = eZCLI::instance();
    
    if (!file_exists($newPath)) {
        if (!file_exists($oldPath)) {
            $cli->warning('Source file not exist : ' . $oldPath);
            return false;
        }
    
        eZDir::mkdir( dirname( $newPath ), false, true );
        $success = copy($oldPath, $newPath);
        
        $cli = eZCLI::instance();
        if ($success) {
            $fileToRemove[] = $oldPath;
            $cli->notice('Move ' . $oldPath . ' => ' . $newPath);
        } else {
            $cli->warning('Fail to move ' . $oldPath . ' => ' . $newPath);
        }
    } else {
        $fileToRemove[] = $oldPath;
    }
    
    return $success;
}
Example #3
0
function changeSiteAccessSetting($siteAccess)
{
    $cli = eZCLI::instance();
    if (in_array($siteAccess, eZINI::instance()->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) {
        $cli->output("Using siteaccess {$siteAccess} for nice url update");
    } else {
        $cli->notice("Siteaccess {$siteAccess} does not exist, using default siteaccess");
    }
}
Example #4
0
function changeSiteAccessSetting($siteAccess)
{
    $cli = eZCLI::instance();
    if (file_exists('settings/siteaccess/' . $siteAccess)) {
        $cli->output("Using siteaccess {$siteAccess} for nice url update");
    } else {
        $cli->notice("Siteaccess {$siteAccess} does not exist, using default siteaccess");
    }
}
 public static function execute($exclusiveParentID = 1)
 {
     $db = eZDB::instance();
     $cli = eZCLI::instance();
     //1. delete the assignments from eznode_assignment table
     // delete the assignments which don't have relevant entry in ezconentobject_tree
     // select the data that doesn't exist in either eznode_assignment or ezcontentobject_tree
     $deletedAssignmentList = $db->arrayQuery("SELECT * FROM eznode_assignment WHERE id NOT IN " . "(SELECT assign.id FROM eznode_assignment assign, ezcontentobject_tree tree WHERE " . "assign.contentobject_id = tree.contentobject_id AND assign.parent_node = tree.parent_node_id)");
     $deletedCount = 0;
     foreach ($deletedAssignmentList as $deletedAssignment) {
         // select the content object which is published.
         //If the object of the assignment is in trash or draft, it's not the one to be deleted
         $tempAssignID = $deletedAssignment["id"];
         $content = eZContentObject::fetch($deletedAssignment["contentobject_id"], false);
         if ($content && $deletedAssignment['parent_node'] != $exclusiveParentID) {
             if ($content["status"] == eZContentObject::STATUS_PUBLISHED) {
                 // iterate the data to be deleted, delete them
                 $cli->notice('Node assignment [ id: ' . $deletedAssignment['id'] . ' ] for contentobject [ id: ' . $deletedAssignment['contentobject_id'] . ' ] is not consistent with entries in contentobject_tree' . ' table thus will be removed.');
                 $sql = "DELETE FROM eznode_assignment WHERE id = " . $tempAssignID;
                 $result = $db->query($sql);
                 if ($result === false) {
                     $cli->notice('Node assignment [ id: ' . $deletedAssignment['id'] . ' ] ' . 'could not be removed. Please restore your database from backup and try again.');
                     return;
                 }
                 $deletedCount++;
             }
         }
     }
     //2. Delete the duplicated entries which have same contentobject_id, contentobject_version and is_main
     // The process of deleting duplicated entries deletes the old entries, keeps the latest entry in the
     // duplicated entry list.
     $tempDeleteList = array();
     $duplicatedContentList = $db->arrayQuery("SELECT contentobject_id, contentobject_version, is_main, parent_node\n                                              FROM eznode_assignment\n                                              GROUP BY contentobject_id, contentobject_version, is_main, parent_node\n                                              HAVING COUNT(*) > 1");
     foreach ($duplicatedContentList as $duplicatedContent) {
         $assignmentList = $db->arrayQuery("SELECT * FROM eznode_assignment" . " WHERE contentobject_id = " . $duplicatedContent['contentobject_id'] . " AND contentobject_version = " . $duplicatedContent["contentobject_version"] . " AND parent_node =" . $duplicatedContent["parent_node"] . " ORDER BY id DESC");
         $assignmentListCount = count($assignmentList);
         //Find the duplicated entries( array index start from 1 ) and delete them. Leave the one entry( array index is 0 )
         for ($i = 1; $i < $assignmentListCount; $i++) {
             if ($assignmentList[$i]["parent_node"] != $exclusiveParentID) {
                 $tempAssignID = $assignmentList[$i]["id"];
                 $cli->notice('Node assignment [ id: ' . $tempAssignID . ' ] for contentobject [ id: ' . $assignmentList[$i]["contentobject_id"] . '] is duplicated thus will be removed.');
                 $sql = "DELETE FROM eznode_assignment WHERE id = " . $tempAssignID;
                 $result = $db->query($sql);
                 if ($result === false) {
                     $cli->notice('Node assignment [ id: ' . $tempAssignID . ' ] ' . 'could not be removed. Please restore your database from backup and try again.');
                     return;
                 }
                 $deletedCount++;
             }
         }
     }
     if ($deletedCount != 0) {
         $cli->output($deletedCount . ' node assignments have been deleted.');
     } else {
         $cli->output('None of available node assignments has been deleted.');
     }
 }
Example #6
0
function changeSiteAccessSetting(&$siteaccess, $optionData)
{
    $cli = eZCLI::instance();
    if (file_exists('settings/siteaccess/' . $optionData)) {
        $siteaccess = $optionData;
        $cli->output("Using siteaccess {$siteaccess} for cronjob");
    } else {
        $cli->notice("Siteaccess {$optionData} does not exist, using default siteaccess");
    }
}
function changeSiteAccessSetting(&$siteaccess, $optionData)
{
    $cli = eZCLI::instance();
    if (in_array($optionData, eZINI::instance()->variable('SiteAccessSettings', 'AvailableSiteAccessList'))) {
        $siteaccess = $optionData;
        $cli->output("Using siteaccess {$siteaccess} for content object name update");
    } else {
        $cli->notice("Siteaccess {$optionData} does not exist, using default siteaccess");
    }
}
Example #8
0
function updateClass($classId, $scheduledScript)
{
    $cli = eZCLI::instance();
    /*
    // If the class is not stored yet, store it now
    $class = eZContentClass::fetch( $classId, true, eZContentClass::VERSION_STATUS_TEMPORARY );
    if ( $class )
    {
        $cli->output( "Storing class" );
        $class->storeDefined( $class->fetchAttributes() );
    }
    */
    // Fetch the stored class
    $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_MODIFIED);
    if (!$class) {
        $cli->error('No class in a modified version status with ID: ' . $classId);
        return;
    }
    // Fetch attributes and definitions
    $attributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_MODIFIED);
    $oldClassAttributes = $class->fetchAttributes($classId, true, eZContentClass::VERSION_STATUS_DEFINED);
    // Delete object attributes which have been removed.
    foreach ($oldClassAttributes as $oldClassAttribute) {
        $attributeExist = false;
        $oldClassAttributeID = $oldClassAttribute->attribute('id');
        foreach ($attributes as $newClassAttribute) {
            if ($oldClassAttributeID == $newClassAttribute->attribute('id')) {
                $attributeExist = true;
            }
        }
        if (!$attributeExist) {
            foreach (eZContentObjectAttribute::fetchSameClassAttributeIDList($oldClassAttributeID) as $objectAttribute) {
                $objectAttribute->removeThis($objectAttribute->attribute('id'));
            }
        }
    }
    $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED);
    // Add object attributes which have been added.
    foreach ($attributes as $newClassAttribute) {
        $attributeExist = false;
        foreach ($oldClassAttributes as $oldClassAttribute) {
            if ($oldClassAttribute->attribute('id') == $newClassAttribute->attribute('id')) {
                $attributeExist = true;
                break;
            }
        }
        if (!$attributeExist) {
            $objects = null;
            $newClassAttribute->initializeObjectAttributes($objects);
        }
    }
    if ($scheduledScript !== false) {
        $scheduledScript->updateProgress(100);
    }
}
Example #9
0
 public function reportProgress($filename, $count)
 {
     static $progress = array('|', '/', '-', '\\');
     if ($count == 0) {
         $this->cli->output($this->cli->storePosition() . " " . $this->cli->restorePosition(), false);
     } else {
         $text = array_shift($progress);
         $this->cli->output($this->cli->storePosition() . $text . $this->cli->restorePosition(), false);
         $progress[] = $text;
     }
 }
Example #10
0
function changeSiteAccessSetting(&$siteaccess, $optionData)
{
    $ini = eZINI::instance();
    $cli = eZCLI::instance();
    $availableSiteAccessList = $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList');
    if (in_array($optionData, $availableSiteAccessList)) {
        $siteaccess = $optionData;
        $cli->output("Using siteaccess {$siteaccess} for database cleanup");
    } else {
        $cli->notice("Siteaccess {$optionData} does not exist, using default siteaccess");
    }
}
    /**
     * Executes the purge operation
     *
     * @todo Endless loop on fetch list. The expired items are returned over and over again
     */
    public function run()
    {
        $cli = eZCLI::instance();

        if ( $this->optMemoryMonitoring == true )
        {
            eZLog::rotateLog( self::LOG_FILE );
            $cli->output( "Logging memory usage to " . self::LOG_FILE );
        }

        if ( $this->optIterationSleep > 0 )
            $sleep = ( $this->optIterationSleep * 1000000 );
        else
            $sleep = false;

        $limit = array( 0, $this->optIterationLimit );

        $cli->output( "Purging expired items:" );

        self::monitor( "start" );

        // Fetch a limited list of purge items from the handler itself
        $clusterHandler = eZClusterFileHandler::instance();
        while ( $filesList = $clusterHandler->fetchExpiredItems( $this->optScopes, $limit, $this->optExpiry ) )
        {
            self::monitor( "iteration start" );
            foreach( $filesList as $file )
            {
                $cli->output( "- $file" );
                if ( $this->optDryRun == false )
                {
                    self::monitor( "purge" );
                    $fh = eZClusterFileHandler::instance( $file );
                    $fh->purge( false, false );
                    unset( $fh );
                }
            }
            if ( $sleep !== false )
                usleep( $sleep );

            // the offset only has to be increased in dry run mode
            // since each batch is not deleted
            if ( $this->optDryRun == true )
            {
                $limit[0] += $limit[1];
            }
            self::monitor( "iteration end" );
        }

        self::monitor( "end" );
    }
function changeSiteAccessSetting(&$siteaccess, $optionData)
{
    $cli = eZCLI::instance();
    if (file_exists('settings/siteaccess/' . $optionData)) {
        $siteaccess = $optionData;
        return "Using siteaccess {$siteaccess} for cronjob";
    } elseif (isExtensionSiteaccess($optionData)) {
        $siteaccess = $optionData;
        eZExtension::prependExtensionSiteAccesses($siteaccess);
        return "Using extension siteaccess {$siteaccess} for cronjob";
    } else {
        return "Siteaccess {$optionData} does not exist, using default siteaccess";
    }
}
Example #13
0
function changeSiteAccessSetting(&$siteaccess, $optionData)
{
    global $cronPart;
    $cli = eZCLI::instance();
    if (file_exists('settings/siteaccess/' . $optionData)) {
        $siteaccess = $optionData;
        $cli->output("Using siteaccess {$siteaccess} for cronjob");
    } elseif (isExtensionSiteaccess($optionData)) {
        $siteaccess = $optionData;
        $cli->output("Using extension siteaccess {$siteaccess} for cronjob");
        eZExtension::prependExtensionSiteAccesses($siteaccess);
    } else {
        $cli->notice("Siteaccess {$optionData} does not exist, using default siteaccess");
    }
}
Example #14
0
function changeSiteAccessSetting(&$siteaccess, $optionData)
{
    global $isQuiet;
    $cli = eZCLI::instance();
    if (file_exists('settings/siteaccess/' . $optionData)) {
        $siteaccess = $optionData;
        if (!$isQuiet) {
            $cli->notice("Using siteaccess {$siteaccess} for database cleanup");
        }
    } else {
        if (!$isQuiet) {
            $cli->notice("Siteaccess {$optionData} does not exist, using default siteaccess");
        }
    }
}
 /**
  * Saves the xml content
  *
  * @param $filename Path to file
  */
 function save($filename = 'sitemap.xml')
 {
     $file = eZClusterFileHandler::instance($filename);
     if ($file->exists()) {
         eZDebug::writeDebug("Time: " . date('d.m.Y H:i:s') . ". Action: " . $filename . " exists. File will be remove.");
         if (!$isQuiet) {
             $cli = eZCLI::instance();
             $cli->output("Time: " . date('d.m.Y H:i:s') . ". Action: " . $filename . " exists. File will be remove.");
             $cli->output("\n");
         }
         $file->delete();
     }
     $xml = $this->dom->saveXML();
     return $file->storeContents($xml, 'sitemap', 'text/xml');
 }
function testConnection($parameters)
{
    $cli = eZCLI::instance();
    #$connection = eZClusterSMTP::connect( $parameters );
    $connection = eZClusterSMTP::instance($parameters);
    if (count($connection->errors) == 0) {
        $cli->output("Connected to " . $parameters['host']);
        return true;
    } else {
        $cli->output("ERROR while connecting to " . $parameters['host']);
        foreach ($connection->errors as $error) {
            $cli->output("Server Respond: " . $error);
        }
        return false;
    }
    $connection->quit();
}
Example #17
0
 function warning($text, $position = false)
 {
     if ($position) {
         $str = $position['file'] . ':' . $position['from'][0] . ' C' . $position['from'][1];
         if (isset($position['to'])) {
             $str .= ' -> L' . $position['to'][0] . ' C' . $position['to'][1];
         }
         $str .= ':';
     }
     $str .= $text;
     if (class_exists('ezcli')) {
         $cli = eZCLI::instance();
         $cli->warning($str);
     } else {
         eZDebug::writeWarning($str, __METHOD__);
     }
 }
 function runOperation(&$node)
 {
     $object = $node->attribute('object');
     $object_id = $object->attribute('id');
     $objectLocales = $object->attribute('available_languages');
     // If the new locale does not exist for object, create it
     if (!in_array($this->newLocale, $objectLocales)) {
         // Create a new version of the original in another locale.
         $cli = eZCLI::instance();
         $cli->output("Copying the single translation in {$this->orgLocale} to {$this->newLocale}");
         $newVersion = $object->createNewVersionIn($this->newLocale, $this->orgLocale, false, true, eZContentObjectVersion::STATUS_DRAFT);
         $publishResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object_id, 'version' => $newVersion->attribute('version')));
         eZContentObject::clearCache();
         $object = eZContentObject::fetch($object_id);
     }
     return true;
 }
    private static function generateCSS( $force = false )
    {
        $cli = eZCLI::instance();
        $cli->output("\n Generating css files");

        foreach ( glob('extension/*/design/*/stylesheets/*.less') as $lessFilePath )
        {
            $lessFile = new KLessFile($lessFilePath);
            if ( $force )
            {
                $lessFile->compile();
            }
            else
            {
                $lessFile->compileIfNeeded();
            }
        }
    }
    /**
     * @param array $possibleReplies
     * @param array $alreadyChosen
     */
    function showReplies ( $possibleReplies, $alreadyChosen = array() )
    {
        if ( count($possibleReplies) > 0 )
        {
            $this->cli->output( "Expected Reply between [ ]" );

            foreach ( $possibleReplies as $label => $description )
            {
                if ( in_array($label, $alreadyChosen) )
                {
                    $this->cli->warning( " * [$label] : $description" );
                }
                else
                {
                    $this->cli->output( "   [$label] : $description" );
                }
            }
        }
    }
/**
 * @param $clusters
 * @param $options
 * @return void
 */
function generateCache($clusters, $options) {
    $cli = eZCLI::instance();

    foreach ( $clusters as $clusterPath )
    {
        $clusterIdentifier = basename( $clusterPath );

        $configurations = MMRssGenerator::createConfigurationsForCluster( $clusterIdentifier );
        foreach ( $configurations as $type => $configType )
        {
            foreach ( $configType as $frequency => $config )
            {
                $cli->output( "$clusterIdentifier - $type - $frequency" );
                $params = array(
                    'type' => $type,
                    'frequency' => $frequency,
                );

                //set date to daily, weekly and monthly
                if(isset($options['begin' . ucfirst($frequency)]) && !empty($options['begin' . ucfirst($frequency)])) {
                    //test if end frequence is set
                    if(!isset($options['end' . ucfirst($frequency)])) {
                        $options['end' . ucfirst($frequency)] = '*';
                    }

                    if(empty($options['end' . ucfirst($frequency)])) {
                        $options['end' . ucfirst($frequency)] = '*';
                    }

                    //add frequence date parameters
                    $params['beginDate'] = $options['begin' . ucfirst($frequency)];
                    $params['endDate'] = $options['end' . ucfirst($frequency)];

                    //if date params set, use different path
                    $params['path'] = "/rssManualCache/";
                }

                $rssGenerator = new MMRssGenerator( $params, $clusterIdentifier );
                $rssGenerator->getXML( true );
            }
        }
    }
}
/**
 * Fix xml attributes for empty images that have been trashed.
 *
 * @param $imageAttribute
 * @param $optDryRun bool   if in dry-run mode (do not update DB row)
 */
function fixupTrashedImageXml($imageAttribute, $optDryRun)
{
    if (stripos($imageAttribute['data_text'], ' dirpath="/trashed" ') === false || stripos($imageAttribute['data_text'], ' is_valid="" ') === false) {
        return;
    }
    $id = $imageAttribute['id'];
    $contentId = $imageAttribute['contentobject_id'];
    $version = $imageAttribute['version'];
    eZCLI::instance()->notice("Processing image {$contentId} ({$version}) ...");
    if (($doc = simplexml_load_string($imageAttribute['data_text'])) === false) {
        continue;
    }
    $doc['filename'] = '';
    $doc['basename'] = '';
    $doc['dirpath'] = '';
    $doc['url'] = '';
    $imageXml = $doc->asXml();
    if (!$optDryRun) {
        eZDB::instance()->query("UPDATE ezcontentobject_attribute SET data_text='{$imageXml}' WHERE id='{$id}' and version='{$version}'");
    }
}
/**
 * Updates non-breaking spaces from existing "&amp;nbsp;" to proper "\xC2\xA0"
 *
 * @param array $attribute
 */
function updateEzxmlNonbreakSpaces($attribute, $optDryRun, $verbose)
{
    $id = $attribute['id'];
    $contentId = $attribute['contentobject_id'];
    $version = $attribute['version'];
    $xmlData = $attribute['data_text'];
    $matchTags = implode('|', array('paragraph', 'header'));
    $pattern = '/(<(?<tag>' . $matchTags . ')[^>]*\\>)(.*)&amp;nbsp;(.*)(<\\/(?P=tag)>)/';
    $replace = "\\1\\3 \\4\\5";
    do {
        $xmlData = preg_replace($pattern, $replace, $xmlData, -1, $countReplaced);
    } while ($countReplaced > 0);
    if ($verbose) {
        eZCLI::instance()->output("Updating data for content #{$contentId} (ver. {$version}) ...");
    }
    if (!$optDryRun) {
        $db = eZDB::instance();
        $xmlData = $db->escapeString($xmlData);
        $db->query("UPDATE ezcontentobject_attribute SET data_text='{$xmlData}' WHERE id='{$id}'");
    }
}
function dfsCleanup($directory)
{
    list($host, $user, $pass, $db, $port, $socket, $mountPoint) = eZINI::instance("file.ini")->variableMulti("eZDFSClusteringSettings", array("DBHost", "DBUser", "DBPassword", "DBName", "DBPort", "DBSocket", "MountPointPath"));
    $db = new mysqli($host, $user, $pass, $db, $port, $socket);
    // Replacing \ and / by a regex equivalent matching both.
    $imagesDirectory = str_replace(array("\\", "/"), "[\\\\/]", rtrim($directory, "\\/"));
    $db->query("\n        DELETE FROM ezdfsfile\n        WHERE scope = 'image' AND\n        name REGEXP '^{$imagesDirectory}[\\\\/].*[\\\\/].*[\\\\/]trashed[\\\\/]'");
    $db->close();
    array_map("filesystemCleanup", glob("{$mountPoint}/{$directory}/*"));
}
require "autoload.php";
$script = eZScript::instance(array("description" => "eZ Publish trashed images sanitizer script (#017781).", "use-session" => false, "use-modules" => false, "use-extensions" => true));
$script->startup();
$options = $script->getOptions("[n]", "", array("-q" => "Quiet mode", "n" => "Do not wait"));
$script->initialize();
$cli = eZCLI::instance();
if (!isset($options['n'])) {
    $cli->warning("This cleanup script will remove any images from trashed objects.");
    $cli->warning("For more details about this cleanup, take a look at: http://issues.ez.no/17781.");
    $cli->warning();
    $cli->warning("IT IS YOUR RESPONSABILITY TO TAKE CARE THAT NO ITEMS REMAINS IN TRASH BEFORE RUNNING THIS SCRIPT.");
    $cli->warning();
    $cli->warning("You have 30 seconds to break the script (press Ctrl-C).");
    sleep(30);
}
$fileHandler = eZINI::instance("file.ini")->variable("ClusteringSettings", "FileHandler");
$directory = eZSys::varDirectory() . "/storage/images";
switch (strtolower($fileHandler)) {
    case "ezfsfilehandler":
    case "ezfs2filehandler":
        array_map("filesystemCleanup", glob("{$directory}/*"));
Example #25
0
 function getOptions($config, $argumentConfig, $arguments = false)
 {
     $program = false;
     if ($arguments === false) {
         $arguments = $GLOBALS['argv'];
         $program = $arguments[0];
         array_shift($arguments);
     }
     if (is_string($config)) {
         $config = eZCLI::parseOptionString($config, $tmpConfig);
     }
     if (is_string($argumentConfig)) {
         $argumentConfig = eZCLI::parseOptionString($argumentConfig, $tmpArgumentConfig);
     }
     $options = array();
     $helpOption = false;
     $helpText = false;
     if (isset($config['short']['h'])) {
         $helpOption = '-h';
     } else {
         if (isset($config['short']['help'])) {
             $helpOption = '--help';
         }
     }
     if ($helpOption) {
         $helpText = "\n" . "Try `{$program} {$helpOption}' for more information.";
     }
     $options['arguments'] = array();
     $arguments = array_values($arguments);
     $argumentCount = count($arguments);
     for ($i = 0; $i < $argumentCount; ++$i) {
         $argument = $arguments[$i];
         $argumentLen = strlen($argument);
         if ($argumentLen > 1 and $argument[0] == '-') {
             $argumentValue = false;
             if ($argumentLen > 2 and $argument[1] == '-') {
                 $optionName = substr($argument, 2);
                 $assignPosition = strpos($optionName, '=');
                 if ($assignPosition !== false) {
                     $argumentValue = substr($optionName, $assignPosition + 1);
                     $optionName = substr($optionName, 0, $assignPosition);
                 }
                 $optionType = 'long';
                 $optionPrefix = '--';
                 $checkNext = false;
             } else {
                 $optionName = $argument[1];
                 if ($argumentLen > 2) {
                     $argumentValue = substr($argument, 2);
                 }
                 $optionType = 'short';
                 $optionPrefix = '-';
                 $checkNext = true;
             }
             $configItem =& $config[$optionType][$optionName];
             if (isset($configItem)) {
                 $value = true;
                 $hasValue = $configItem['has-value'];
                 $hasMultipleValues = ($configItem['quantifier']['min'] > 1 or $configItem['quantifier']['max'] === false or $configItem['quantifier']['max'] > 1);
                 if ($hasValue) {
                     $hasArgumentValue = false;
                     if ($argumentValue !== false) {
                         $value = $argumentValue;
                     } else {
                         if ($checkNext and $configItem['has-value'] !== 'optional') {
                             ++$i;
                             if ($i < $argumentCount) {
                                 $hasArgumentValue = true;
                             } else {
                                 --$i;
                                 $this->error("{$program}: option `{$optionPrefix}{$optionName}' requires an argument" . $helpText);
                                 return false;
                             }
                             if ($hasArgumentValue) {
                                 $value = $arguments[$i];
                             }
                         } else {
                             if ($configItem['has-value'] !== 'optional') {
                                 $this->error("{$program}: option `{$optionPrefix}{$optionName}' requires an argument" . $helpText);
                                 return false;
                             }
                         }
                     }
                 }
                 $optionStoreName = $configItem['store-name'];
                 if (!$optionStoreName) {
                     $optionStoreName = $optionName;
                 }
                 if ($hasMultipleValues) {
                     if (!isset($options[$optionStoreName])) {
                         $options[$optionStoreName] = array();
                     }
                     $options[$optionStoreName][] = $value;
                 } else {
                     $options[$optionStoreName] = $value;
                 }
             } else {
                 $this->error("{$program}: invalid option `{$optionPrefix}{$optionName}'" . $helpText);
                 return false;
             }
         } else {
             $options['arguments'][] = $argument;
         }
     }
     foreach ($config['list'] as $configItem) {
         $optionStoreName = $configItem['store-name'];
         if ($optionStoreName and !isset($options[$optionStoreName])) {
             $options[$optionStoreName] = null;
         }
     }
     return $options;
 }
<?php

$env = eZINI::instance('site.ini')->variable('Environment', 'Type');

if ($env != 'stg')
{
    eZCLI::instance()->output('This cronjob will only work on stg env');
    eZExecution::cleanExit();
}

$db = eZDB::instance();

/* regenerate sprite for only pending clusters */
$sql = "SELECT distinct(param)
           FROM ezpending_actions
           WHERE action = 'generate_app_sprite'";


$actions = $db->arrayQuery( $sql );

if (empty($actions))
{
    eZExecution::cleanExit();
}

$spriteTool = new SpriteTool();
foreach ( $actions as $action )
{
    $result = $spriteTool->generateSpriteForCluster( $action['param'] );
    if ($result['errorCode'] == 0)
    {
Example #27
0
function setEZXMLAttribute($attribute, $attributeValue, $link = false)
{
    $contentObjectID = $attribute->attribute("contentobject_id");
    $parser = new eZSimplifiedXMLInputParser($contentObjectID, false, 0, false);
    $attributeValue = str_replace("\r", '', $attributeValue);
    $attributeValue = str_replace("\n", '', $attributeValue);
    $attributeValue = str_replace("\t", ' ', $attributeValue);
    $document = $parser->process($attributeValue);
    if (!is_object($document)) {
        $cli = eZCLI::instance();
        $cli->output('Error in xml parsing');
        return;
    }
    $domString = eZXMLTextType::domString($document);
    $attribute->setAttribute('data_text', $domString);
    $attribute->store();
}
Example #28
0
<?php

/**
 * Trash purge cronjob
 *
 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 * @version  2012.6
 * @package kernel
 */
$purgeHandler = new eZScriptTrashPurge(eZCLI::instance());
$purgeHandler->run();
    public static function exportConfig($clusterIdentifier)
    {
        $db = MMDB::instance();
        $cli = eZCLI::instance();
        $config = array();

        $cli->output($clusterIdentifier);

        // GENERAL ABOUT CLUSTER
        $localized["view"] = ezpI18n::tr("merck", "NO VIEW");
        $localized["views"] = ezpI18n::tr("merck", "VIEWS");
        $localized["rating"] = ezpI18n::tr("merck", "NO RATING");
        $localized["ratings"] = ezpI18n::tr("merck", "RATING");
        $localized["dateForm"] = str_replace('%', '', eZINI::instance("date.ini")->variable($clusterIdentifier, 'DateFormat'));
        $localized["altDescription"] = ezpI18n::tr("seo", "ACTUALITIES");
        $config["localized"] = $localized;

        ClusterTool::setCurrentCluster($clusterIdentifier);
        // About application
        foreach($db->arrayQuery(sprintf("SELECT DISTINCT(application_identifier) FROM mm_seo WHERE cluster_identifier = '%s'", $clusterIdentifier)) as $row)
        {
            $applicationIdentifier = $row["application_identifier"];
            $filters = array();
            $config[$applicationIdentifier] = array();

            $appLocalized = ApplicationLocalized::getLocalizedApplicationByIdentifier($applicationIdentifier, $clusterIdentifier);
            $appUrl = $appLocalized->attribute('url');
            /** @var ContentListBase $app */
            $app = ApplicationFactory::fetchByUri( '/'.$appUrl );

            $isContentApplication = ( $app instanceof ContentListBase);
            if ( !$isContentApplication )
            {
                continue;
            }

            // CREATE FILTER
            $solrFilter = $app->getResultHandler()->solrFilter();
            $solrFacetsFiler = $app->getResultHandler()->solrFacetsFilter();
            if( $solrFilter )
                $filters[] = $solrFilter;
            if( $solrFacetsFiler )
                $filters[] = $solrFacetsFiler;

            $filters = implode(' AND ', $filters);
            $config[$applicationIdentifier]["filters"] = $filters;

            // CREATE MAPPING PUBLISHERS
            $publishers = array();
            foreach($app->applicationLocalized()->publisherFolders as $publisherFolder)
            {
                $publishers[$publisherFolder->attribute("path")] = $publisherFolder->getTranslation()->attribute("name");
            }
            $config[$applicationIdentifier]["publishers"] = $publishers;

            // CREATE CONFIGURATION TAGLINE
            $features = $app->resultHandler->features;
            $config[$applicationIdentifier]["tagline"] = $features["line"];
        }

        return $config;
    }
function getNextSendDateDaily($newNewsletter)
{
    $cli = eZCLI::instance();
    //get next senddate
    $counter = 1;
    while (true) {
        if ($counter > 7) {
            $next_date = false;
            break;
        }
        $next_date = mktime($newNewsletter->attribute('send_hour'), $newNewsletter->attribute('send_minute'), $newNewsletter->attribute('send_second'), $newNewsletter->attribute('send_month'), $newNewsletter->attribute('send_day') + $counter, $newNewsletter->attribute('send_year'));
        if (is_numeric(strpos($newNewsletter->attribute('recurrence_value'), date("w", $next_date)))) {
            break;
        }
        $counter = $counter + 1;
    }
    //set next senddate
    $date = mktime($newNewsletter->attribute('send_hour'), $newNewsletter->attribute('send_minute'), $newNewsletter->attribute('send_second'), date("m", $next_date), date("d", $next_date), date("Y", $next_date));
    return $date;
}