Пример #1
0
 /**
  * Concatenates one or more foreach-able object into an Iterator.
  * If no objects provided, returns an empty iterator.
  * \AppendIterators provided will be deep copied.
  * 		This means changes to \AppendIterator parameters will not be reflected
  * 		in the resulting \Iterator.
  * @return \Iterator
  */
 public static function concat()
 {
     $argCount = \func_num_args();
     if ($argCount === 0) {
         return new \EmptyIterator();
     } elseif ($argCount === 1) {
         return Iterators::ensureIsIterator(\func_get_args()[0]);
     } else {
         $retval = new \AppendIterator();
         //Workaround for AppendIterator bugs
         //https://bugs.php.net/bug.php?id=49104
         //https://bugs.php.net/bug.php?id=62212
         $retval->append(new \ArrayIterator([0]));
         unset($retval->getArrayIterator()[0]);
         $recursiveAttach = static function ($iter) use(&$recursiveAttach, $retval) {
             foreach ($iter as $concatedIter) {
                 if ($concatedIter instanceof \AppendIterator) {
                     $recursiveAttach($concatedIter->getArrayIterator());
                 } elseif ($concatedIter instanceof \EmptyIterator) {
                     //Do not add it.
                 } else {
                     $retval->append($concatedIter);
                 }
             }
             return $retval;
         };
         return (new \Yasca\Core\FunctionPipe())->wrap(\func_get_args())->pipe([Iterators::_class, 'ensureIsIterator'])->pipe([Iterators::_class, 'select'], [Iterators::_class, 'ensureIsIterator'])->pipe($recursiveAttach)->unwrap();
     }
 }
Пример #2
0
 /**
  * For each async tasks scheduled, execute its tick function synchronously.
  * Executing the tick function on an Async will unschedule it if the Async completes.
  * Do not use with declare(ticks=...) and register_tick_function
  * as that feature is deprecated as of PHP 5.3.0.
  * Instead, consider making a call for each event loop at the top level in your script.
  * @return true|false True if there are currently scheduled Asyncs
  */
 public static function tickAll()
 {
     //tickables() are allowed to register new tickables
     //Make sure that these are not lost.
     $snapshotOfAsyncs = self::$asyncs;
     self::$asyncs = Iterators::toList([]);
     self::$asyncs = (new \Yasca\Core\IteratorBuilder())->from($snapshotOfAsyncs)->where(static function ($async) {
         return $async->tick() === false;
     })->toFunctionPipe()->pipe([Iterators::_class, 'toList'])->toIteratorBuilder()->concat(self::$asyncs)->toList();
     return self::$asyncs->isEmpty() === false;
 }
Пример #3
0
	public function unique(){
		$this->iterator = Iterators::unique($this->iterator);
		return $this;
	}
Пример #4
0
 /**
  * Copies elements of this fluent iterator into an array.
  * @return array
  */
 public function toArray()
 {
     return Iterators::toArray($this->iterator);
 }
Пример #5
0
<?php

// example: SERVER_ID=5915 php maintenance/wikia/GoogleWebmasterToolsSync/initial_sync.php --conf /usr/wikia/docroot/wiki.factory/LocalSettings.php
global $IP;
require_once __DIR__ . "/common.php";
GWTLogHelper::notice(__FILE__ . " script starts.");
$minCountOfPagesToSync = 100;
try {
    global $wgExternalSharedDB, $wgDatamartDB;
    $wikiPageCountService = (new WikiPageCountServiceFactory())->get();
    $wikiRepository = new GWTWikiRepository();
    foreach (Iterators::group($wikiPageCountService->listPageCountsIterator(), 50) as $pageCountGroup) {
        $updated = 0;
        $created = 0;
        $same = 0;
        GWTLogHelper::debug("Group size: " . (int) count($pageCountGroup));
        foreach ($pageCountGroup as $pageCountModel) {
            /** @var WikiPageCountModel $pageCountModel */
            $page = $wikiRepository->getById($pageCountModel->getWikiId());
            if ($page == null) {
                $wikiRepository->insert($pageCountModel->getWikiId(), null, null, $pageCountModel->getPageCount());
                $created++;
            } else {
                if ($page->getPageCount() != $pageCountModel->getPageCount()) {
                    $page->setPageCount($pageCountModel->getPageCount());
                    $wikiRepository->updateWiki($page);
                    $updated++;
                } else {
                    $same++;
                }
            }