/** * Unit test for fetchByName() method */ public function testFetchByName() { $name = 'foo'; $row = array('name' => $name, 'value' => 'bar'); $obj = new eZSiteData($row); $obj->store(); unset($obj); $res = eZSiteData::fetchByName($name); $this->assertInstanceOf('eZSiteData', $res); $res->remove(); }
<?php require 'autoload.php'; $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => "Clean sqliimporttoken", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true)); $script->startup(); $options = $script->getOptions('[start][stop]', '', array('start' => 'Start rsync status', 'stop' => 'Stop rssync status')); $script->initialize(); $script->setUseDebugAccumulators(true); $rsyncStatusName = 'rsync_status'; $statusRunning = 1; $statusHalted = 0; $rsyncStatus = eZSiteData::fetchByName($rsyncStatusName); if (!$rsyncStatus) { $row = array('name' => 'rsync_status', 'value' => $statusHalted); $rsyncStatus = new eZSiteData($row); } if ($options['stop']) { $rsyncStatus->setAttribute('value', $statusHalted); } elseif ($options['start']) { $rsyncStatus->setAttribute('value', $statusRunning); } $rsyncStatus->store(); $cli->output("Rsync status: " . $rsyncStatus->attribute('value')); $script->shutdown();
public static function importTripDatabase($month, $batch, $area) { echo "--------------------------------\r\n Importing 'Trip Database' data\r\n--------------------------------\r\n"; $minMonth = ((self::$autoMode) ? self::$month : (is_null($month) ? 1 : $month)); $minBatch = ((self::$autoMode) ? self::$batch : (is_null($batch) ? 1 : $batch)); $maxMonth = ((self::$autoMode) ? self::$month+1 : (is_null($month) ? 13: $month+1)); $maxBatch = ((self::$autoMode) ? self::$batch+1 : (is_null($batch) ? 6 : $batch+1)); $areas = is_null($area) ? self::$areas : array($area); $jsonArticles = array(); foreach($areas as $area) { for($month = $minMonth; $month<$maxMonth ; $month++) { self::$month = $month; for($batch=$minBatch; $batch<$maxBatch ; $batch++) { self::$batch = $batch; $xmlResponse = self::curlCallTripAPI($area); $jsonArticles[] = self::processXML($xmlResponse); } } } foreach($jsonArticles as $container) { foreach($container as $article) { $solrIndexationJob = new SolrIndexationJob(null); $solrIndexationJob->setAttribute('data', $article); $solrIndexationJob->store(); } } $log = new eZSiteData(null); $log->setAttribute('name', 'trip_last_import_date'); $log->setAttribute('value', self::$year.'-'.self::$month.'-'.self::$batch); $log->store(); echo "\r\n".self::$totalProcessed." articles were found and imported.\r\nRun process_solr_indexation_jobs to import them into SolR.\r\n"; echo "\r\nEnd of script. Bye!\r\n\r\n"; }
public static function createSitemap($archive = false) { $cli = eZCLI::instance(); $xrowsitemapINI = eZINI::instance('xrowsitemap.ini'); if (!$xrowsitemapINI->hasVariable('Settings', 'Archive') or $xrowsitemapINI->variable('Settings', 'Archive') != 'disabled') { if ($xrowsitemapINI->hasVariable('Settings', 'ArchiveTimeShift')) { $offset = 3600 * 24 * (int) $xrowsitemapINI->variable('Settings', 'ArchiveTimeShift'); } else { $offset = 3600 * 24 * 30; } $time = eZSiteData::fetchByName(self::SITEDATA_ARCHIVE_KEY); if (!$time) { $row = array('name' => self::SITEDATA_ARCHIVE_KEY, 'value' => time() - $offset); $time = new eZSiteData($row); $time->store(); } if ($archive) { $time = eZSiteData::fetchByName(self::SITEDATA_ARCHIVE_KEY); $time->setAttribute('value', time() - $offset); $time->store(); } $timestamp = $time->attribute('value'); } eZDebug::writeDebug("Generating sitemap ...", __METHOD__); if (!$isQuiet) { $cli->output("Generating sitemap for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n"); } if ($xrowsitemapINI->hasVariable('SitemapSettings', 'ClassFilterType') and $xrowsitemapINI->hasVariable('SitemapSettings', 'ClassFilterArray')) { $params2 = array('ClassFilterType' => $xrowsitemapINI->variable('SitemapSettings', 'ClassFilterType'), 'ClassFilterArray' => $xrowsitemapINI->variable('SitemapSettings', 'ClassFilterArray')); } $max = self::MAX_PER_FILE; if ($xrowsitemapINI->hasVariable('SitemapSettings', 'LimitPerLoop')) { $limit = (int) $xrowsitemapINI->variable('SitemapSettings', 'LimitPerLoop'); } else { $limit = self::DEFAULT_LIMIT; } if ($limit > $max) { $cli->output("LimitPerLoop can`t be larger as MAX_PER_FILE. LimitPerLoop is set to MAX_PER_FILE\n"); $limit = $max; } // Fetch the content tree $params = array('SortBy' => array(array('depth', true), array('published', true))); if (isset($timestamp) and $archive === true) { $params['AttributeFilter'] = array(array('published', '<=', $timestamp)); } elseif (isset($timestamp) and $archive === false) { $params['AttributeFilter'] = array(array('published', '>', $timestamp)); } if ($xrowsitemapINI->hasVariable('SitemapSettings', 'ExtraAttributeFilter')) { $extra_attribute_filter = array(); $extra_attribute_filter = $xrowsitemapINI->variable('SitemapSettings', 'ExtraAttributeFilter'); } if (isset($extra_attribute_filter)) { foreach ($extra_attribute_filter as $key => $extra_attribute_filter_item) { if ($xrowsitemapINI->hasGroup($extra_attribute_filter_item)) { $value = $xrowsitemapINI->variable($extra_attribute_filter_item, 'Value'); array_push($params['AttributeFilter'], $value); } } } if ($xrowsitemapINI->hasVariable('SitemapSettings', 'MainNodeOnly') && $xrowsitemapINI->Variable('SitemapSettings', 'MainNodeOnly') == "true") { $params['MainNodeOnly'] = true; } if (isset($params2)) { $params = array_merge($params, $params2); } $rootNode = self::rootNode(); $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID); if ($subtreeCount <= 1) { # could be an old installation with no fresh content! //throw new Exception( "No Items found under RootNode $rootNode->NodeID." ); return; } $sitemap = new xrowSitemap(); // Generate Sitemap self::addNode($sitemap, $rootNode); $max = min($max, $subtreeCount); $max_all = $max; $params['Limit'] = $limit; $params['Offset'] = 0; $counter = 1; $runs = ceil($subtreeCount / $max_all); if (!$isQuiet) { $amount = $subtreeCount + 1; // for root node $cli->output("Adding {$amount} nodes to the sitemap for RootNode {$rootNode->NodeID}."); $output = new ezcConsoleOutput(); } // write XML Sitemap to file if ($archive) { $filetyp = self::FILETYP_ARCHIVE; } else { $filetyp = self::FILETYP_STANDARD; } $dir = eZSys::storageDirectory() . '/sitemap/' . self::domain() . '/' . $filetyp; $cachedir = eZSys::cacheDirectory() . '/sitemap/' . self::domain() . '/' . $filetyp; $sitemapfiles = array(); $tmpsitemapfiles = array(); while ($counter <= $runs) { eZDebug::writeDebug('Run ' . $counter . ' of ' . $runs . ' runs'); if (!$isQuiet) { $cli->output('Run ' . $counter . ' of ' . $runs . ' runs'); if ($counter == 1) { $bar = new ezcConsoleProgressbar($output, $max + 1); // for root node } else { $bar = new ezcConsoleProgressbar($output, $max); } } while ($params['Offset'] < $max_all) { $nodeArray = eZContentObjectTreeNode::subTreeByNodeID($params, $rootNode->NodeID); foreach ($nodeArray as $subTreeNode) { self::addNode($sitemap, $subTreeNode); if (isset($bar)) { $bar->advance(); } } eZContentObject::clearCache(); $params['Offset'] += $params['Limit']; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } if (!is_dir($cachedir)) { mkdir($cachedir, 0777, true); } $filename = xrowSitemap::BASENAME . '_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX; if ($counter > 1) { $filename = xrowSitemap::BASENAME . '_' . $GLOBALS['eZCurrentAccess']['name'] . '_' . $counter . '.' . xrowSitemap::SUFFIX; } $sitemapfiles[] = $dir . "/" . $filename; $tmpsitemapfiles[] = $cachedir . "/" . $filename; if ($sitemap->saveLocal($cachedir . "/" . $filename) === false) { throw new ezcBaseFileIoException($filename, ezcBaseFileException::WRITE, 'Could not write data to cache file.'); } if (!$isQuiet) { $cli->output("\n"); $cli->output("Time: " . date('d.m.Y H:i:s') . ". Action: Sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been generated in {$cachedir}.\n"); } /** * @TODO How will this work with cluster? if ( function_exists( 'gzencode' ) and $xrowsitemapINI->variable( 'SitemapSettings', 'Gzip' ) == 'enabled' ) { $content = file_get_contents( $filename ); $content = gzencode( $content ); file_put_contents( $filename . '.gz', $content ); unlink( $filename ); $filename .= '.gz'; } **/ $counter++; $max_all += $max; $sitemap = new xrowSitemap(); } $handler = eZClusterFileHandler::instance(); if ($handler instanceof eZDFSFileHandler or $handler instanceof eZDBFileHandler) { self::cleanDir($cachedir); } //move all from cache to cluster filesystem foreach ($sitemapfiles as $key => $sitemapfile) { $file = eZClusterFileHandler::instance($sitemapfile); $file->storeContents(file_get_contents($tmpsitemapfiles[$key]), 'sitemap', 'text/xml'); if (!$isQuiet) { $cli->output("\n"); $cli->output("Time: " . date('d.m.Y H:i:s') . ". Action: Sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been moved to {$dir}.\n"); } if ($handler instanceof eZDFSFileHandler or $handler instanceof eZDBFileHandler) { unlink($tmpsitemapfiles[$key]); } } if ($handler instanceof eZFSFileHandler) { self::cleanDir($cachedir); } }
/** * return void */ protected function logImport() { $log = new eZSiteData(null); $log->setAttribute('name', $this->application->name . '_last_import_date'); $log->store(); }
/** * return void */ protected function logImport() { $log = new eZSiteData(null); $log->setAttribute('name', 'congress_report_rss_last_import_date'); $log->store(); }