コード例 #1
0
    /**
     * @param string $clusterIdentifier
     * @throws eZDBException
     */
    public static function fill($clusterIdentifier)
    {
        $configPath = "extension/ezoscar/bin/php/seo/config.json";
        $cli = eZCLI::instance();

        $config = file_get_contents($configPath);
        if(!$config)
        {
            $cli->output("Bad filepath for config file");
            eZExecution::cleanExit();
        }

        $config = json_decode($config, true);

        $db = MMDB::instance();

        $rows = $db->arrayQuery(sprintf("SELECT * FROM mm_seo WHERE cluster_identifier = '%s'", $clusterIdentifier));
        $progressBar = new ezcConsoleProgressbar( new ezcConsoleOutput(), count($rows), array(
            'emptyChar' => ' ',
            'barChar'   => '='
        ) );
        $progressBar->start();

        foreach($rows as $row)
        {
            if(!array_key_exists($clusterIdentifier, $config))
            {
                continue;
            }

            $fq = $config[$clusterIdentifier][$row["application_identifier"]]["filters"];

            $solrBase = new eZSolrBase();
            $params = array(
                'indent'       => 'on',
                'q'            => '"'.$row['keyword'].'"',
                'fq'           => $fq,
                'start'        => 0,
                'rows'         => 0,
                'fl'           => '',
                'qt'           => 'ezpublish',
                'explainOther' => '',
                'hl.fl'        => '',
            );

            $results = $solrBase->rawSolrRequest('/select', $params);
            $num_found = $results['response']['numFound'];
            $db->query(sprintf("UPDATE mm_seo SET nb_results=%d, speciality_url='%s', keyword_url='%s' WHERE id=%d",
                $num_found,
                self::sanitize($row["speciality"]),
                self::sanitize($row["keyword"]),
                $row["id"]));

            $progressBar->advance();
        }
        $progressBar->finish();
        $cli->output();
    }
コード例 #2
0
 /**
  * Copy & Paste Detection (CPD).
  *
  * @param  Iterator|array $files     List of files to process
  * @param  integer        $minLines  Minimum number of identical lines
  * @param  integer        $minTokens Minimum number of identical tokens
  * @return CodeCloneMap   Map of exact clones found in the list of files
  */
 public function copyPasteDetection($files, $minLines = 5, $minTokens = 70)
 {
     $result = new CodeCloneMap();
     if ($this->output !== NULL) {
         $bar = new \ezcConsoleProgressbar($this->output, count($files));
         print "Processing files\n";
     }
     foreach ($files as $file) {
         $this->strategy->processFile($file, $minLines, $minTokens, $result);
         if ($this->output !== NULL) {
             $bar->advance();
         }
     }
     if ($this->output !== NULL) {
         print "\n\n";
     }
     return $result;
 }
コード例 #3
0
ファイル: progressbar_test.php プロジェクト: bmdevel/ezc
 private function commonProgressbarTest($refFile, $max, $step, $options)
 {
     $out = new ezcConsoleOutput();
     $bar = new ezcConsoleProgressbar($out, $max, $options);
     if ($step != 1) {
         $bar->options->step = $step;
     }
     $res = array();
     for ($i = 0; $i < $max; $i += $step) {
         ob_start();
         $bar->advance();
         //            sleep( 1 );
         $resTmp = ob_get_clean();
         if (trim($resTmp) !== '') {
             $res[] = $resTmp;
         }
     }
     $refFile = dirname(__FILE__) . '/data/' . (ezcBaseFeatures::os() === "Windows" ? "windows/" : "posix/") . $refFile . '.dat';
     // Use the following line to regenerate test reference files
     // file_put_contents( $refFile, implode( PHP_EOL, $res ) );
     $expected = file_exists($refFile) ? file_get_contents($refFile) : '';
     $this->assertEquals($expected, implode(PHP_EOL, $res), 'Progressbar not correctly generated for ' . $refFile . '.');
 }
コード例 #4
0
try
{
    $output->outputLine( 'Looking for obsolete image files...' );

    // Fetch all image files in ezimagefile table
    $aImageFiles = eZPersistentObject::fetchObjectList( eZImageFile::definition() );
    $nbImageFiles = count( $aImageFiles );

    if( $nbImageFiles > 0 )
    {
        // Progress bar initialization
        $progressBarOptions = array(
            'emptyChar'     => ' ',
            'barChar'       => '='
        );
        $progressBar = new ezcConsoleProgressbar( $output, $nbImageFiles, $progressBarOptions );

        // Loop the image files and check if it is still used by a content object attribute. If not, delete it.
        foreach( $aImageFiles as $image )
        {
            $filePath = $image->attribute( 'filepath' );
            $dirpath = dirname( $filePath );
            $contentObjectAttributeID = $image->attribute( 'contentobject_attribute_id' );
            $dbResult = eZImageFile::fetchImageAttributesByFilepath( $filePath, $contentObjectAttributeID );
            if( count( $dbResult ) == 0 )
            {
                $file = eZClusterFileHandler::instance( $filePath );
                if ( $file->exists() ) // Delete the file physically
                {
                    $file->delete();
                    eZImageFile::removeFilepath( $contentObjectAttributeID, $filePath );
コード例 #5
0
 * @license http://ez.no/licenses/new_bsd New BSD License
 */
require_once 'Base/src/base.php';
/**
 * Autoload ezc classes 
 * 
 * @param string $className 
 */
function __autoload($className)
{
    ezcBase::autoload($className);
}
$out = new ezcConsoleOutput();
$out->formats->red->color = "red";
// Create progress bar itself
$progress = new ezcConsoleProgressbar($out, 100, array('step' => 5));
$progress->options->emptyChar = '-';
$progress->options->progressChar = $out->formatText('>', "red");
$progress->options->formatString = "Uploading file </tmp/foobar.tar.bz2>: %act%/%max% kb [%bar%]";
// Perform actions
$i = 0;
while ($i++ < 20) {
    // Do whatever you want to indicate progress for
    usleep(mt_rand(20000, 2000000));
    // Advance the progressbar by one step ( uploading 5k per run )
    $progress->advance();
}
// Finish progress bar and jump to next line.
$progress->finish();
$out->outputText("Successfully uploaded </tmp/foobar.tar.bz2>.\n", 'success');
/*
コード例 #6
0
ファイル: generate.php プロジェクト: heliopsis/xrowmetadata
     if (isset($bar)) {
         $bar->advance();
     }
 }
 if (!$isQuiet) {
     $cli->output();
     $cli->output('Adding manual items');
 }
 $manualItems = $googlesitemapsINI->variable('SiteMapSettings', 'AddUrlArray');
 $manualPriority = $googlesitemapsINI->variable('SiteMapSettings', 'AddPriorityArray');
 $manualFrequency = $googlesitemapsINI->variable('SiteMapSettings', 'AddFrequencyArray');
 $itemCount = count($manualItems);
 if (!$isQuiet) {
     $cli->output("Found {$itemCount} entries");
     $output = new ezcConsoleOutput();
     $bar = new ezcConsoleProgressbar($output, $itemCount);
 }
 foreach ($manualItems as $mKey => $mItem) {
     $url = $mItem;
     eZURI::transformURI($url, true, 'full');
     if (isset($manualPriority[$mKey])) {
         $prio = $manualPriority[$mKey];
     } else {
         $prio = null;
     }
     if (isset($manualFrequency[$mKey])) {
         $freq = $manualFrequency[$mKey];
     } else {
         $freq = null;
     }
     $sitemap->add($url, null, $freq, $prio);
コード例 #7
0
 public static function createMFSitemap()
 {
     eZDebug::writeDebug("Generating Standard Sitemap with images ...", __METHOD__);
     $cli = $GLOBALS['cli'];
     global $cli, $isQuiet;
     if (!$isQuiet) {
         $cli->output("Generating Sitemap for Siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
     }
     $ini = eZINI::instance('site.ini');
     $googlesitemapsINI = eZINI::instance('xrowsitemap.ini');
     // Get the Sitemap's root node
     $contentINI = eZINI::instance('content.ini');
     $rootNode = eZContentObjectTreeNode::fetch($contentINI->variable('NodeSettings', 'RootNode'));
     if (!$rootNode instanceof eZContentObjectTreeNode) {
         $cli->output("Invalid RootNode for Siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
         continue;
     }
     // Settings variables
     if ($googlesitemapsINI->hasVariable('MFSitemapSettings', 'ClassFilterType') and $googlesitemapsINI->hasVariable('MFSitemapSettings', 'ClassFilterArray')) {
         $params2 = array('ClassFilterType' => $googlesitemapsINI->variable('MFSitemapSettings', 'ClassFilterType'), 'ClassFilterArray' => $googlesitemapsINI->variable('MFSitemapSettings', 'ClassFilterArray'));
     }
     $max = 49997;
     // max. amount of links in 1 sitemap
     $limit = 50;
     // Fetch the content tree
     $params = array('SortBy' => array(array('depth', true), array('published', false)));
     if (isset($params2)) {
         $params = array_merge($params, $params2);
     }
     $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID);
     if ($subtreeCount == 1) {
         $cli->output("No Items found under node #" . $contentINI->variable('NodeSettings', 'RootNode') . ".");
     }
     if (!$isQuiet) {
         $amount = $subtreeCount + 1;
         // +1 is root node
         $cli->output("Adding {$amount} nodes to the sitemap.");
         $output = new ezcConsoleOutput();
         $bar = new ezcConsoleProgressbar($output, $amount);
     }
     $addPrio = false;
     if ($googlesitemapsINI->hasVariable('MFSitemapSettings', 'AddPriorityToSubtree') and $googlesitemapsINI->variable('MFSitemapSettings', 'AddPriorityToSubtree') == 'true') {
         $addPrio = true;
     }
     $sitemap = new xrowSitemap();
     // Generate Sitemap
     /** START Adding the root node **/
     $object = $rootNode->object();
     $meta = xrowMetaDataFunctions::fetchByObject($object);
     $extensions = array();
     $extensions[] = new xrowSitemapItemModified($rootNode->attribute('modified_subnode'));
     $url = $rootNode->attribute('url_alias');
     eZURI::transformURI($url, true);
     if ($ini->variable('SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess') == 'enabled') {
         $url = 'http://' . xrowSitemapTools::domain() . $url;
     } else {
         $url = 'http://' . xrowSitemapTools::domain() . '/' . $GLOBALS['eZCurrentAccess']['name'] . $url;
     }
     if ($meta and $meta->googlemap != '0') {
         $extensions[] = new xrowSitemapItemFrequency($meta->change);
         $extensions[] = new xrowSitemapItemPriority($meta->priority);
         $sitemap->add($url, $extensions);
     } elseif ($meta === false and $googlesitemapsINI->variable('Settings', 'AlwaysAdd') == 'enabled') {
         if ($addPrio) {
             $extensions[] = new xrowSitemapItemPriority('1');
         }
         $sitemap->add($url, $extensions);
     }
     if (isset($bar)) {
         $bar->advance();
     }
     /** END Adding the root node **/
     $max = min($max, $subtreeCount);
     $params['Limit'] = min($max, $limit);
     $params['Offset'] = 0;
     while ($params['Offset'] < $max) {
         $nodeArray = eZContentObjectTreeNode::subTreeByNodeID($params, $rootNode->NodeID);
         foreach ($nodeArray as $subTreeNode) {
             eZContentLanguage::expireCache();
             $object = $subTreeNode->object();
             $images = array();
             $meta = xrowMetaDataFunctions::fetchByObject($object);
             $extensions = array();
             $extensions[] = new xrowSitemapItemModified($subTreeNode->attribute('modified_subnode'));
             $url = $subTreeNode->attribute('url_alias');
             eZURI::transformURI($url, true);
             if ($ini->variable('SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess') == 'enabled') {
                 $url = 'http://' . xrowSitemapTools::domain() . $url;
             } else {
                 $url = 'http://' . xrowSitemapTools::domain() . '/' . $GLOBALS['eZCurrentAccess']['name'] . $url;
             }
             if ($meta and $meta->googlemap != '0') {
                 $extensions[] = new xrowSitemapItemFrequency($meta->change);
                 $extensions[] = new xrowSitemapItemPriority($meta->priority);
             } elseif ($meta === false and $googlesitemapsINI->variable('Settings', 'AlwaysAdd') == 'enabled') {
                 if ($addPrio) {
                     $rootDepth = $rootNode->attribute('depth');
                     $prio = 1 - ($subTreeNode->attribute('depth') - $rootDepth) / 10;
                     if ($prio > 0) {
                         $extensions[] = new xrowSitemapItemPriority($prio);
                     }
                 }
             }
             $images = self::getSitemapImageItems($object);
             $sitemap->add($url, array_merge($extensions, $images));
             if (isset($bar)) {
                 $bar->advance();
             }
         }
         eZContentObject::clearCache();
         $params['Offset'] += $params['Limit'];
     }
     // write XML Sitemap to file
     $dir = eZSys::storageDirectory() . '/sitemap/' . xrowSitemapTools::domain();
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $filename = $dir . '/' . xrowSitemap::BASENAME . '_standard_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX;
     $sitemap->save($filename);
     if (!$isQuiet) {
         $cli->output("\n");
         $cli->output("Sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been generated.\n");
     }
 }
コード例 #8
0
<?php

require_once 'tutorial_autoload.php';
$output = new ezcConsoleOutput();
$output->formats->bar->color = 'blue';
$output->formats->bar->style = array('bold');
$options = array('emptyChar' => ' ', 'barChar' => '-', 'formatString' => '%fraction%% <' . $output->formatText('%bar%', 'bar') . '> Uploaded %act% / %max% kb', 'redrawFrequency' => 50);
$bar = new ezcConsoleProgressbar($output, 1024, $options);
for ($i = 0; $i < 1024; $i++) {
    $bar->advance();
    usleep(mt_rand(200, 2000));
}
$bar->finish();
$output->outputLine();
コード例 #9
0
ファイル: Detector.php プロジェクト: hpbuniat/phpcpd
 /**
  * Copy & Paste Detection (CPD).
  *
  * @param  Iterator|array   $files     List of files to process
  * @param  integer          $minLines  Minimum number of identical lines
  * @param  integer          $minTokens Minimum number of identical tokens
  */
 public function copyPasteDetection($files, $minLines = 5, $minTokens = 70)
 {
     $oMap = new PHPCPD_CloneMap();
     if ($this->output !== NULL) {
         $bar = new ezcConsoleProgressbar($this->output, count($files));
         print 'Processing files' . PHP_EOL;
     }
     $this->strategy->init($oMap, $minLines, $minTokens);
     $oTokenizer = new PHPCPD_Detector_Tokenizer();
     foreach ($files as $file) {
         $oTokenizer->process($this->strategy, $oMap, $file);
         if ($this->output !== NULL) {
             $bar->advance();
         }
     }
     if ($this->output !== NULL) {
         print PHP_EOL . PHP_EOL;
     }
     return $oMap;
 }
コード例 #10
0
 /**
  * Clears view cache for imported content objects.
  * ObjectIDs are stored in 'ezpending_actions' table, with {@link SQLIContent::ACTION_CLEAR_CACHE} action
  */
 public static function viewCacheClear()
 {
     $db = eZDB::instance();
     $isCli = isset($_SERVER['argv']);
     $output = null;
     $progressBar = null;
     $i = 0;
     $conds = array('action' => SQLIContent::ACTION_CLEAR_CACHE);
     $limit = array('offset' => 0, 'length' => 50);
     $count = (int) eZPersistentObject::count(eZPendingActions::definition(), $conds);
     if ($isCli && $count > 0) {
         // Progress bar implementation
         $output = new ezcConsoleOutput();
         $output->outputLine('Starting to clear view cache for imported objects...');
         $progressBarOptions = array('emptyChar' => ' ', 'barChar' => '=');
         $progressBar = new ezcConsoleProgressbar($output, $count, $progressBarOptions);
         $progressBar->start();
     }
     /*
      * To avoid fatal errors due to memory exhaustion, pending actions are fetched by packets
      */
     do {
         $aObjectsToClear = eZPendingActions::fetchObjectList(eZPendingActions::definition(), null, $conds, null, $limit);
         $jMax = count($aObjectsToClear);
         if ($jMax > 0) {
             for ($j = 0; $j < $jMax; ++$j) {
                 if ($isCli) {
                     $progressBar->advance();
                 }
                 $db->begin();
                 eZContentCacheManager::clearContentCacheIfNeeded((int) $aObjectsToClear[$j]->attribute('param'));
                 $aObjectsToClear[$j]->remove();
                 $db->commit();
                 $i++;
             }
         }
         unset($aObjectsToClear);
         eZContentObject::clearCache();
         if (eZINI::instance('site.ini')->variable('ContentSettings', 'StaticCache') == 'enabled') {
             $optionArray = array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'StaticCacheHandler');
             $options = new ezpExtensionOptions($optionArray);
             $staticCacheHandler = eZExtension::getHandlerClass($options);
             $staticCacheHandler::executeActions();
         }
     } while ($i < $count);
     if ($isCli && $count > 0) {
         $progressBar->finish();
         $output->outputLine();
     }
 }
コード例 #11
0
 /**
  * Starts to run the import
  * @param array( SQLIImportItem ) $aImportItems
  * @throws SQLIImportBaseException
  * @throws ezcConfigurationNoConfigException
  */
 public function runImport(array $aImportItems)
 {
     // First check if an import is already running
     if (SQLIImportToken::importIsRunning()) {
         throw new SQLIImportBaseException('Another import is already running. Aborting...', SQLIImportBaseException::IMPORT_ALREADY_RUNNING);
     }
     $this->token = SQLIImportToken::registerNewImport();
     $this->handlePerformanceSettings();
     if (empty($aImportItems)) {
         // If no source handler is provided, consider processing all source handlers available
         $aImportItems = $this->importINI->variable('ImportSettings', 'AvailableSourceHandlers');
     }
     // Process import items one by one
     for ($i = 0, $iMax = count($aImportItems); $i < $iMax; ++$i) {
         try {
             if (!$aImportItems[$i] instanceof SQLIImportItem) {
                 throw new SQLIImportRuntimeException('Invalid import item !');
             }
             // Update status for import item
             $aImportItems[$i]->setAttribute('status', SQLIImportItem::STATUS_RUNNING);
             $aImportItems[$i]->store();
             $this->currentImportItem = $aImportItems[$i];
             // First check if this handler has all needed configuration
             $handler = $aImportItems[$i]->attribute('handler');
             $handlerSection = $handler . '-HandlerSettings';
             if (!$this->importINI->hasSection($handlerSection)) {
                 // Check INI Section
                 throw new ezcConfigurationNoConfigException('Error : Handler "' . $handler . '" does not have proper config section in sqliimport.ini !');
             }
             if (!$this->importINI->hasVariable($handlerSection, 'ClassName')) {
                 // Check if ClassName is properly defined
                 throw new ezcConfigurationNoConfigException('Error : ClassName not defined for "' . $handler . '" in sqliimport.ini !');
             }
             // Default values
             $handlerClassName = $this->importINI->variable($handlerSection, 'ClassName');
             $handlerEnabled = true;
             $debug = false;
             $defaultParentNodeID = $this->importINI->variable('ImportSettings', 'DefaultParentNodeID');
             $streamTimeout = $this->importINI->variable('ImportSettings', 'StreamTimeout');
             if ($this->importINI->hasVariable($handlerSection, 'Enabled')) {
                 $handlerEnabled = $this->importINI->variable($handlerSection, 'Enabled') === 'true';
             }
             if ($this->importINI->hasVariable($handlerSection, 'Debug')) {
                 $debug = $this->importINI->variable($handlerSection, 'Debug') === 'enabled';
             }
             if ($this->importINI->hasVariable($handlerSection, 'DefaultParentNodeID')) {
                 $localParentNodeID = $this->importINI->variable($handlerSection, 'DefaultParentNodeID');
                 $defaultParentNodeID = is_int($localParentNodeID) ? (int) $localParentNode : $defaultParentNodeID;
             }
             if ($this->importINI->hasVariable($handlerSection, 'StreamTimeout')) {
                 $streamTimeout = (int) $this->importINI->variable($handlerSection, 'StreamTimeout');
             }
             // Check $defaultParentNodeID and throw an exception if not consistent
             $parentNode = eZContentObjectTreeNode::fetch($defaultParentNodeID, false, false);
             if (!$parentNode) {
                 throw new SQLIImportRuntimeException('Error : invalid DefaultParentNodeID ( ' . $defaultParentNodeID . ' )');
             }
             unset($parentNode);
             // Check handler class validity
             if (!class_exists($handlerClassName)) {
                 throw new SQLIImportRuntimeException('Error : invalid handler class "' . $handlerClassName . '". Did you regenerate autolads ?');
             }
             // ####################################
             // ##### IMPORT HANDLER PROCESSING
             // ####################################
             // Instantiate the handler with appropriate options and process it.
             // Handler must implement ISQLIImportHandler and extend SQLIImportAbstractHandler
             $handlerOptions = $aImportItems[$i]->attribute('options');
             $importHandler = new $handlerClassName($handlerOptions);
             if (!$importHandler instanceof ISQLIImportHandler || !$importHandler instanceof SQLIImportAbstractHandler) {
                 throw new SQLIImportRuntimeException('Error : invalid handler "' . $handlerClassName . '". Must implement ISQLIImportHandler and extend SQLIImportAbstractHandler.');
             }
             $importHandler->handlerConfArray = $this->importINI->group($handlerSection);
             $importHandler->initialize();
             // Get process length to calculate advancement percentage to track advancement
             $processLength = $importHandler->getProcessLength();
             $percentageAdvancementStep = 100 / $processLength;
             $handlerName = $importHandler->getHandlerName();
             $handlerIdentifier = $importHandler->getHandlerIdentifier();
             // Progress bar implementation
             $progressBarOptions = array('emptyChar' => ' ', 'barChar' => '=');
             $progressBar = new ezcConsoleProgressbar($this->output, $processLength, $progressBarOptions);
             $progressBar->start();
             $this->cli->warning('Now processing "' . $handlerName . '" handler.');
             $isInterrupted = false;
             while ($row = $importHandler->getNextRow()) {
                 try {
                     $progressBar->advance();
                     $startTime = time();
                     $importHandler->process($row);
                 } catch (Exception $e) {
                     SQLIImportLogger::logError('An error occurred during "' . $handlerIdentifier . '" import process : ' . $e->getMessage());
                 }
                 $aImportItems[$i]->updateProgress($percentageAdvancementStep, $importHandler->getProgressionNotes());
                 // Now calculate process time for this iteration
                 $endTime = time();
                 $diffTime = $endTime - $startTime;
                 $oldProcessTime = $aImportItems[$i]->attribute('process_time');
                 $aImportItems[$i]->setAttribute('process_time', $oldProcessTime + $diffTime);
                 $aImportItems[$i]->store(array('process_time'));
                 // Interruption handling
                 if ($aImportItems[$i]->isInterrupted()) {
                     $this->cli->notice();
                     SQLIImportLogger::logNotice('Interruption has been requested for current import ! Cleaning and aborting process...');
                     $isInterrupted = true;
                     break;
                 }
             }
             $importHandler->cleanup();
             $progressBar->finish();
             $this->cli->notice();
             unset($importHandler);
             if (!$isInterrupted) {
                 $aImportItems[$i]->setAttribute('status', SQLIImportItem::STATUS_COMPLETED);
                 $aImportItems[$i]->setAttribute('percentage', 100);
                 // Force percentage to 100%
                 $aImportItems[$i]->store();
             }
             // ####################################
             // ##### END IMPORT HANDLER PROCESSING
             // ####################################
         } catch (Exception $e) {
             SQLIImportLogger::logError($e->getMessage());
             $aImportItems[$i]->setAttribute('status', SQLIImportItem::STATUS_FAILED);
             $aImportItems[$i]->store();
             if (isset($importHandler)) {
                 $importHandler->cleanup();
                 unset($importHandler);
             }
             continue;
         }
     }
 }
コード例 #12
0
 public static function createMobileSitemap()
 {
     eZDebug::writeDebug("Generating mobile sitemap ...", __METHOD__);
     $cli = eZCLI::instance();
     if (!$isQuiet) {
         $cli->output("Generating mobile sitemap for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
     }
     $ini = eZINI::instance('site.ini');
     $xrowsitemapINI = eZINI::instance('xrowsitemap.ini');
     // Get the Sitemap's root node
     $rootNode = self::rootNode();
     // Settings variables
     if ($xrowsitemapINI->hasVariable('MobileSitemapSettings', 'ClassFilterType') and $xrowsitemapINI->hasVariable('MobileSitemapSettings', 'ClassFilterArray')) {
         $params2 = array('ClassFilterType' => $xrowsitemapINI->variable('MobileSitemapSettings', 'ClassFilterType'), 'ClassFilterArray' => $xrowsitemapINI->variable('MobileSitemapSettings', 'ClassFilterArray'));
     }
     $max = self::MAX_PER_FILE;
     $limit = 50;
     // Fetch the content tree
     $params = array('SortBy' => array(array('depth', true), array('published', true)));
     if (isset($params2)) {
         $params = array_merge($params, $params2);
     }
     $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID);
     if ($subtreeCount == 1) {
         $cli->output("No Items found under RootNode {$rootNode->NodeID}.");
     }
     if (!$isQuiet) {
         $amount = $subtreeCount + 1;
         // +1 is root node
         $cli->output("Adding {$amount} nodes to the sitemap for RootNode {$rootNode->NodeID}.");
         $output = new ezcConsoleOutput();
         $bar = new ezcConsoleProgressbar($output, $amount);
     }
     $addPrio = false;
     if ($xrowsitemapINI->hasVariable('Settings', 'AddPriorityToSubtree') and $xrowsitemapINI->variable('Settings', 'AddPriorityToSubtree') == 'true') {
         $addPrio = true;
     }
     $sitemap = new xrowMobileSitemap();
     // Generate Sitemap
     /** START Adding the root node **/
     $object = $rootNode->object();
     $meta = xrowMetaDataFunctions::fetchByObject($object);
     $extensions = array();
     $extensions[] = new xrowSitemapItemModified($rootNode->attribute('modified_subnode'));
     $url = $rootNode->attribute('url_alias');
     eZURI::transformURI($url);
     if ($xrowsitemapINI->hasVariable('SitemapSettings', 'MobileDomainName') && $xrowsitemapINI->hasVariable('SitemapSettings', 'MobileDomainName') != '') {
         $mobileDomain = $xrowsitemapINI->variable('SitemapSettings', 'MobileDomainName');
     } else {
         $mobileDomain = self::domain();
     }
     $url = 'http://' . $mobileDomain . $url;
     if ($meta and $meta->sitemap_use != '0') {
         $extensions[] = new xrowSitemapItemFrequency($meta->change);
         $extensions[] = new xrowSitemapItemPriority($meta->priority);
         $sitemap->add($url, $extensions);
     } elseif ($meta === false and $xrowsitemapINI->variable('Settings', 'AlwaysAdd') == 'enabled') {
         if ($addPrio) {
             $extensions[] = new xrowSitemapItemPriority('1');
         }
         $sitemap->add($url, $extensions);
     }
     if (isset($bar)) {
         $bar->advance();
     }
     /** END Adding the root node **/
     $max = min($max, $subtreeCount);
     $params['Limit'] = min($max, $limit);
     $params['Offset'] = 0;
     while ($params['Offset'] < $max) {
         $nodeArray = eZContentObjectTreeNode::subTreeByNodeID($params, $rootNode->NodeID);
         foreach ($nodeArray as $subTreeNode) {
             eZContentLanguage::expireCache();
             $meta = xrowMetaDataFunctions::fetchByNode($subTreeNode);
             $extensions = array();
             $extensions[] = new xrowSitemapItemModified($subTreeNode->attribute('modified_subnode'));
             $url = $subTreeNode->attribute('url_alias');
             eZURI::transformURI($url);
             $url = 'http://' . $mobileDomain . $url;
             if ($meta and $meta->sitemap_use != '0') {
                 $extensions[] = new xrowSitemapItemFrequency($meta->change);
                 $extensions[] = new xrowSitemapItemPriority($meta->priority);
                 $sitemap->add($url, $extensions);
             } elseif ($meta === false and $xrowsitemapINI->variable('Settings', 'AlwaysAdd') == 'enabled') {
                 if ($addPrio) {
                     $rootDepth = $rootNode->attribute('depth');
                     $prio = 1 - ($subTreeNode->attribute('depth') - $rootDepth) / 10;
                     if ($prio > 0) {
                         $extensions[] = new xrowSitemapItemPriority($prio);
                     }
                 }
                 $sitemap->add($url, $extensions);
             }
             if (isset($bar)) {
                 $bar->advance();
             }
         }
         eZContentObject::clearCache();
         $params['Offset'] += $params['Limit'];
     }
     // write XML Sitemap to file
     $dir = eZSys::storageDirectory() . '/sitemap/' . self::domain();
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $filename = $dir . '/' . xrowSitemap::BASENAME . '_' . self::FILETYP_MOBILE . '_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX;
     $sitemap->save($filename);
     /**
              * @TODO How will this work with cluster?
             if ( function_exists( 'gzencode' ) and $xrowsitemapINI->variable( 'MobileSitemapSettings', 'Gzip' ) == 'enabled' )
             {
                 $content = file_get_contents( $filename );
                 $content = gzencode( $content );
                 file_put_contents( $filename . '.gz', $content );
                 unlink( $filename );
                 $filename .= '.gz';
             }
              **/
     if (!$isQuiet) {
         $cli->output("\n");
         $cli->output("Mobile sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been generated.\n");
     }
 }
コード例 #13
0
ファイル: ezcopy.php プロジェクト: heliopsis/eZCopy
 function spawnDownload($remoteFile, $localFile, $remoteFileSize)
 {
     $cmd = $this->getPathToPHP() . " ./bin/download.php " . $this->data['identifier'] . " " . $remoteFile . " " . $localFile . " > /dev/null 2>&1 &";
     exec($cmd);
     // wait until the archive exist locally
     while (!file_exists($localFile)) {
         usleep(1000);
     }
     $output = new ezcConsoleOutput();
     $bar = new ezcConsoleProgressbar($output, (int) $remoteFileSize);
     $currentStep = 0;
     // until the file is completely downloaded
     do {
         // get current size of local file
         $currentFileSize = $this->getFileSize($localFile);
         $steps = $currentFileSize - $currentStep;
         $bar->advance(true, $steps);
         $currentStep = $currentFileSize;
         // wait for half  second
         usleep(500000);
     } while ($currentFileSize < $remoteFileSize);
     $bar->finish();
 }
コード例 #14
0
 /**
  * Processes a set of files.
  *
  * @param  array   $files
  * @param  boolean $countTests
  * @return array
  * @since  Method available since Release 1.2.0
  */
 public function countFiles(array $files, $countTests)
 {
     if ($countTests) {
         if ($this->output !== NULL) {
             $bar = new ezcConsoleProgressbar($this->output, count($files));
             print "Preprocessing files\n";
         }
         foreach ($files as $file) {
             $this->preProcessFile($file);
             if ($this->output !== NULL) {
                 $bar->advance();
             }
         }
         if ($this->output !== NULL) {
             print "\n\n";
         }
     }
     $directories = array();
     if ($this->output !== NULL) {
         $bar = new ezcConsoleProgressbar($this->output, count($files));
         print "Processing files\n";
     }
     foreach ($files as $file) {
         $directory = dirname($file);
         if (!isset($directories[$directory])) {
             $directories[$directory] = TRUE;
         }
         $this->countFile($file, $countTests);
         if ($this->output !== NULL) {
             $bar->advance();
         }
     }
     if ($this->output !== NULL) {
         print "\n\n";
     }
     $count = $this->count;
     if (!function_exists('bytekit_disassemble_file')) {
         unset($count['eloc']);
     }
     if (!$countTests) {
         unset($count['testClasses']);
         unset($count['testMethods']);
     }
     $count['directories'] = count($directories) - 1;
     $count['namespaces'] = count($this->namespaces);
     $count['classes'] = $count['abstractClasses'] + $count['concreteClasses'];
     $count['methods'] = $count['staticMethods'] + $count['nonStaticMethods'];
     $count['publicMethods'] = $count['methods'] - $count['nonPublicMethods'];
     $count['constants'] = $count['classConstants'] + $count['globalConstants'];
     if (isset($count['eloc']) && $count['eloc'] > 0) {
         $count['ccnByLoc'] = $count['ccn'] / $count['eloc'];
     } else {
         if ($count['ncloc'] > 0) {
             $count['ccnByLoc'] = $count['ccn'] / $count['ncloc'];
         }
     }
     if ($count['methods'] > 0) {
         if (isset($count['testMethods'])) {
             $countTestMethods = $count['testMethods'];
         } else {
             $countTestMethods = 0;
         }
         $count['ccnByNom'] = 1 + $count['ccnMethods'] / ($count['methods'] - $countTestMethods);
     }
     if ($count['classes'] > 0) {
         $count['nclocByNoc'] = $count['nclocClasses'] / $count['classes'];
     }
     if ($count['methods'] > 0) {
         $count['nclocByNom'] = $count['nclocClasses'] / $count['methods'];
     }
     return $count;
 }
コード例 #15
0
 /**
  * @param  array   $files
  * @param  boolean $recursive
  * @return array
  */
 public function detectDeadCode(array $files, $recursive = FALSE)
 {
     $blocks = array();
     $called = array();
     $currentBlock = NULL;
     $currentClass = '';
     $currentFunction = '';
     $currentInterface = '';
     $declared = array();
     $namespace = '';
     $result = array();
     $variables = array();
     if ($this->output !== NULL) {
         $bar = new ezcConsoleProgressbar($this->output, count($files));
         print "\nProcessing files\n";
     }
     foreach ($files as $file) {
         $tokens = new PHP_Token_Stream($file);
         $count = count($tokens);
         for ($i = 0; $i < $count; $i++) {
             if ($tokens[$i] instanceof PHP_Token_NAMESPACE) {
                 $namespace = $tokens[$i]->getName();
             } else {
                 if ($tokens[$i] instanceof PHP_Token_CLASS) {
                     $currentClass = $tokens[$i]->getName();
                     if ($namespace != '') {
                         $currentClass = $namespace . '\\' . $currentClass;
                     }
                     $currentBlock = $currentClass;
                 } else {
                     if ($tokens[$i] instanceof PHP_Token_INTERFACE) {
                         $currentInterface = $tokens[$i]->getName();
                         if ($namespace != '') {
                             $currentInterface = $namespace . '\\' . $currentClass;
                         }
                         $currentBlock = $currentInterface;
                     } else {
                         if ($tokens[$i] instanceof PHP_Token_NEW && !$tokens[$i + 2] instanceof PHP_Token_VARIABLE) {
                             if ($tokens[$i - 1] instanceof PHP_Token_EQUAL) {
                                 $j = -1;
                             } else {
                                 if ($tokens[$i - 1] instanceof PHP_Token_WHITESPACE && $tokens[$i - 2] instanceof PHP_Token_EQUAL) {
                                     $j = -2;
                                 } else {
                                     continue;
                                 }
                             }
                             if ($tokens[$i + $j - 1] instanceof PHP_Token_WHITESPACE) {
                                 $j--;
                             }
                             if ($tokens[$i + $j - 1] instanceof PHP_Token_VARIABLE) {
                                 $name = (string) $tokens[$i + $j - 1];
                                 $variables[$name] = (string) $tokens[$i + 2];
                             } else {
                                 if ($tokens[$i + $j - 1] instanceof PHP_Token_STRING && $tokens[$i + $j - 2] instanceof PHP_Token_OBJECT_OPERATOR && $tokens[$i + $j - 3] instanceof PHP_Token_VARIABLE) {
                                     $name = (string) $tokens[$i + $j - 3] . '->' . (string) $tokens[$i + $j - 1];
                                     $variables[$name] = (string) $tokens[$i + 2];
                                 }
                             }
                         } else {
                             if ($tokens[$i] instanceof PHP_Token_FUNCTION) {
                                 if ($currentInterface != '') {
                                     continue;
                                 }
                                 $function = $tokens[$i]->getName();
                                 if ($function == 'anonymous function') {
                                     continue;
                                 }
                                 $variables = $tokens[$i]->getArguments();
                                 if ($currentClass != '') {
                                     $function = $currentClass . '::' . $function;
                                 }
                                 $currentFunction = $function;
                                 $currentBlock = $currentFunction;
                                 $declared[$function] = array('file' => $file, 'line' => $tokens[$i]->getLine());
                             } else {
                                 if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY) {
                                     array_push($blocks, $currentBlock);
                                     $currentBlock = NULL;
                                 } else {
                                     if ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) {
                                         $block = array_pop($blocks);
                                         if ($block == $currentClass) {
                                             $currentClass = '';
                                         } else {
                                             if ($block == $currentFunction) {
                                                 $currentFunction = '';
                                                 $variables = array();
                                             }
                                         }
                                     } else {
                                         if ($tokens[$i] instanceof PHP_Token_OPEN_BRACKET) {
                                             for ($j = 1; $j <= 4; $j++) {
                                                 if (isset($tokens[$i - $j]) && $tokens[$i - $j] instanceof PHP_Token_FUNCTION) {
                                                     continue 2;
                                                 }
                                             }
                                             if ($tokens[$i - 1] instanceof PHP_Token_STRING) {
                                                 $j = -1;
                                             } else {
                                                 if ($tokens[$i - 1] instanceof PHP_Token_WHITESPACE && $tokens[$i - 2] instanceof PHP_Token_STRING) {
                                                     $j = -2;
                                                 } else {
                                                     continue;
                                                 }
                                             }
                                             $function = (string) $tokens[$i + $j];
                                             $lookForNamespace = TRUE;
                                             if (isset($tokens[$i + $j - 2]) && $tokens[$i + $j - 2] instanceof PHP_Token_NEW) {
                                                 $function .= '::__construct';
                                             } else {
                                                 if (isset($tokens[$i + $j - 1]) && $tokens[$i + $j - 1] instanceof PHP_Token_OBJECT_OPERATOR || isset($tokens[$i + $j - 2]) && $tokens[$i + $j - 2] instanceof PHP_Token_OBJECT_OPERATOR) {
                                                     $_function = $tokens[$i + $j];
                                                     $lookForNamespace = FALSE;
                                                     if ($tokens[$i + $j - 1] instanceof PHP_Token_OBJECT_OPERATOR) {
                                                         $j -= 2;
                                                     } else {
                                                         $j -= 3;
                                                     }
                                                     if ($tokens[$i + $j] instanceof PHP_Token_VARIABLE && isset($variables[(string) $tokens[$i + $j]])) {
                                                         $function = $variables[(string) $tokens[$i + $j]] . '::' . $_function;
                                                     } else {
                                                         if ($tokens[$i + $j] instanceof PHP_Token_STRING && $tokens[$i + $j - 1] instanceof PHP_Token_OBJECT_OPERATOR && $tokens[$i + $j - 2] instanceof PHP_Token_VARIABLE) {
                                                             $variable = (string) $tokens[$i + $j - 2] . '->' . (string) $tokens[$i + $j];
                                                             if (isset($variables[$variable])) {
                                                                 $function = $variables[$variable] . '::' . $_function;
                                                             }
                                                         }
                                                     }
                                                 } else {
                                                     if ($tokens[$i + $j - 1] instanceof PHP_Token_DOUBLE_COLON) {
                                                         $class = $tokens[$i + $j - 2];
                                                         if ($class == 'self' || $class == 'static') {
                                                             $class = $currentClass;
                                                         }
                                                         $function = $class . '::' . $function;
                                                         $j -= 2;
                                                     }
                                                 }
                                             }
                                             if ($lookForNamespace) {
                                                 while ($tokens[$i + $j - 1] instanceof PHP_Token_NS_SEPARATOR) {
                                                     $function = $tokens[$i + $j - 2] . '\\' . $function;
                                                     $j -= 2;
                                                 }
                                             }
                                             if (!isset($called[$function])) {
                                                 $called[$function] = array();
                                             }
                                             $called[$function][] = $currentFunction;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($this->output !== NULL) {
             $bar->advance();
         }
     }
     unset($tokens, $count);
     foreach ($declared as $name => $source) {
         if (!isset($called[$name])) {
             $result[$name] = $source;
         }
     }
     if ($recursive) {
         $done = FALSE;
         while (!$done) {
             $done = TRUE;
             foreach ($called as $callee => $callers) {
                 $_called = FALSE;
                 foreach ($callers as $caller) {
                     if (!isset($result[$caller])) {
                         $_called = TRUE;
                         break;
                     }
                 }
                 if (!$_called) {
                     if (isset($declared[$callee])) {
                         $result[$callee] = $declared[$callee];
                     }
                     $done = FALSE;
                     unset($called[$callee]);
                 }
             }
         }
     }
     ksort($result);
     if ($this->output !== NULL) {
         print "\n";
     }
     return $result;
 }
コード例 #16
0
ファイル: Analyser.php プロジェクト: natmchugh/phploc
 /**
  * Processes a set of files.
  *
  * @param  array   $files
  * @param  boolean $countTests
  * @return array
  * @since  Method available since Release 1.2.0
  */
 public function countFiles(array $files, $countTests)
 {
     if ($countTests) {
         if ($this->output !== NULL) {
             $bar = new ezcConsoleProgressbar($this->output, count($files));
             print "Preprocessing files\n";
         }
         foreach ($files as $file) {
             $this->preProcessFile($file);
             if ($this->output !== NULL) {
                 $bar->advance();
             }
         }
         if ($this->output !== NULL) {
             print "\n\n";
         }
     }
     if ($this->output !== NULL) {
         $bar = new ezcConsoleProgressbar($this->output, count($files));
         print "Processing files\n";
     }
     foreach ($files as $key => $file) {
         $directory = dirname($file);
         if (!isset($this->directories[$directory])) {
             $this->directories[$directory] = TRUE;
         }
         $this->countFile($file, $countTests);
         if ($this->output !== NULL) {
             $bar->advance();
         }
     }
     if ($this->output !== NULL) {
         print "\n\n";
     }
     return $this->getCount($countTests);
 }
コード例 #17
0
ファイル: ezpautoloadclioutput.php プロジェクト: legende91/ez
 /**
  * Finishes progress output for class search phase.
  *
  * Also inserts some extra newlines to make the output clearer.
  *
  * @return void
  */
 public function finishPhase2()
 {
     $this->tokenizerProgress->finish();
     $this->output->outputLine();
     $this->output->outputLine();
 }
コード例 #18
0
 public static function addClassAttributes($class_identifier, $attributesInfo)
 {
     if (isset($class_identifier)) {
         $class = eZContentClass::fetchByIdentifier($class_identifier);
     }
     if (!is_object($class)) {
         return;
     }
     $classID = $class->attribute('id');
     foreach ($attributesInfo as $attributeInfo) {
         $classAttributeIdentifier = $attributeInfo['identifier'];
         $classAttributeName = $attributeInfo['name'];
         $datatype = $attributeInfo['data_type_string'];
         $defaultValue = isset($attributeInfo['default_value']) ? $attributeInfo['default_value'] : false;
         $canTranslate = isset($attributeInfo['can_translate']) ? $attributeInfo['can_translate'] : 1;
         $isRequired = isset($attributeInfo['is_required']) ? $attributeInfo['is_required'] : 0;
         $isSearchable = isset($attributeInfo['is_searchable']) ? $attributeInfo['is_searchable'] : 1;
         $attrContent = isset($attributeInfo['content']) ? $attributeInfo['content'] : false;
         $attrCreateInfo = array('identifier' => $classAttributeIdentifier, 'name' => $classAttributeName, 'can_translate' => $canTranslate, 'is_required' => $isRequired, 'is_searchable' => $isSearchable);
         $newAttribute = eZContentClassAttribute::create($classID, $datatype, $attrCreateInfo);
         $dataType = $newAttribute->dataType();
         $dataType->initializeClassAttribute($newAttribute);
         // not all datatype can have 'default_value'. do check here.
         if ($defaultValue !== false) {
             switch ($datatype) {
                 case 'ezboolean':
                     $newAttribute->setAttribute('data_int3', $defaultValue);
                     break;
                 default:
                     break;
             }
         }
         if ($attrContent) {
             $newAttribute->setContent($attrContent);
         }
         // store attribute, update placement, etc...
         $attributes = $class->fetchAttributes();
         $attributes[] = $newAttribute;
         // remove temporary version
         if ($newAttribute->attribute('id') !== null) {
             $newAttribute->remove();
         }
         $newAttribute->setAttribute('version', eZContentClass::VERSION_STATUS_DEFINED);
         $newAttribute->setAttribute('placement', count($attributes));
         $class->adjustAttributePlacements($attributes);
         foreach ($attributes as $attribute) {
             $attribute->storeDefined();
         }
         // update objects
         $classAttributeID = $newAttribute->attribute('id');
         $count = eZContentObject::fetchSameClassListCount($class->ID);
         $output = new ezcConsoleOutput();
         $bar = new ezcConsoleProgressbar($output, (int) $count);
         $offset = 0;
         $limit = 50;
         while (true) {
             if ($offset > $count) {
                 break;
             }
             $objects = eZContentObject::fetchSameClassList($classID, true, $offset, $limit);
             foreach ($objects as $object) {
                 $contentobjectID = $object->attribute('id');
                 $objectVersions = $object->versions();
                 foreach ($objectVersions as $objectVersion) {
                     $translations = $objectVersion->translations(false);
                     $version = $objectVersion->attribute('version');
                     foreach ($translations as $translation) {
                         $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version);
                         $objectAttribute->setAttribute('language_code', $translation);
                         $objectAttribute->initialize();
                         $objectAttribute->store();
                         $objectAttribute->postInitialize();
                     }
                 }
                 $bar->advance();
             }
             eZContentObject::clearCache();
             $offset += $limit;
         }
         $bar->finish();
     }
 }