示例#1
0
 public function process()
 {
     $start = microtime(true);
     $this->idplist = array();
     $processedEntities = array();
     $i = 0;
     foreach ($this->metadata as $entityId => $metadataEntry) {
         // if (rand(0, 2) === 2) {
         // 	DiscoUtils::log('Skipping random entity: ' . $entityId); continue;
         // }
         DiscoUtils::log('Processing ' . $entityId);
         $entry = new FeedItem($entityId, $this->feedId, $metadataEntry, $this->feedconfig);
         $entry->process();
         $data = $entry->getJSON();
         // echo json_encode($data['disco'], JSON_PRETTY_PRINT) . "\n\n";
         $this->idplist[] = $entry;
         $processedEntities[] = $entityId;
         // if ($i++ > 5) break;
     }
     foreach ($this->idplist as $item) {
         $this->store->insertOrUpdate($item);
     }
     $existingEntries = $this->store->listFeedEntities($this->feedId);
     $toDelete = array_diff($existingEntries, $processedEntities);
     foreach ($toDelete as $td) {
         DiscoUtils::log('Removing entityId ' . $td);
         $this->store->remove($this->feedId, $td);
     }
     if (count($toDelete) === count($processedEntities)) {
         throw new Exception('Will not delete all entities. We assume there is a mistake somewhere... Please fix ASAP.');
     }
     if (count($toDelete) === 0) {
         DiscoUtils::log('All existing entities found, not removing any existing from ' . $this->feedId);
     }
     $end = microtime(true);
     $timer = $end - $start;
     $this->store->logProcess($this->feedId, $timer);
 }
示例#2
0
#!/usr/bin/env php
<?php 
require dirname(dirname(__FILE__)) . '/lib/autoload.php';
$command = new Commando\Command();
$command->option()->describedAs('Command to run: default is update.');
$command->option('f')->aka('feed')->describedAs('The feed identifier to load.');
$command->option('cache-only')->boolean()->describedAs('Do not load metadata, only use existing cache.');
if ($command[0] === 'termcolor') {
    phpterm_demo();
    exit;
}
$backend = new DiscoJuiceBackend();
if ($command['cache-only']) {
    DiscoUtils::log("Running in cache-only mode");
    $backend->enableCacheOnly(true);
}
DiscoUtils::log("DiscoJuice update script. Now updating metadata.", true);
if ($command['feed']) {
    $backend->updateFeed($command['feed']);
} else {
    $backend->update();
}
示例#3
0
#!/usr/bin/env php
<?php 
require dirname(dirname(__FILE__)) . '/lib/autoload.php';
$command = new Commando\Command();
$command->option()->describedAs('Command to run: default is update.');
$command->option('cache-only')->boolean()->describedAs('Do not load metadata, only use existing cache.');
if ($command[0] === 'termcolor') {
    phpterm_demo();
    exit;
}
DiscoUtils::log("DiscoJuice update script. Now updating feide feed.", true);
$fav = Favourites::getByID('uuid:d665541c-2fe6-4843-8752-314587f4edd1');
if ($fav === null) {
    DiscoUtils::log("No favourites found");
    $fav = new Favourites(array('id' => 'uuid:d665541c-2fe6-4843-8752-314587f4edd1', 'favs' => array('foo1', 'foo2', 'bar3')));
    $fav->save();
} else {
    print_r($fav);
}
DiscoUtils::log("Done.");
示例#4
0
 function save()
 {
     $existing = $this->db->{static::$collection}->findOne($this->getQuery());
     if ($existing !== null) {
         $existingItem = self::fromDB($existing);
         if ($this->equalTo($existingItem)) {
             DiscoUtils::log('No changes ' . tc_colored('SKIP', 'cyan') . ' ');
         } else {
             DiscoUtils::log('Object is modified, storing changes ' . tc_colored('UPDATE', 'red') . ' ');
             $this->update();
         }
     } else {
         DiscoUtils::log('Metadata is completely new ' . tc_colored('INSERT', 'green') . ' ');
         $this->insert();
     }
 }
示例#5
0
 function insertOrUpdateFeed($item)
 {
     $query = array('id' => $item['id']);
     $existing = $this->db->feeds->findOne($query);
     if ($existing !== null) {
         foreach ($item as $k => $v) {
             $existing[$k] = $v;
         }
         $existing['update'] = new MongoDate();
         $this->db->feeds->update($query, $existing);
         DiscoUtils::log('Updating feed config ' . tc_colored('UPDATE', 'red') . ' ' . $item['id']);
     } else {
         $item['created'] = new MongoDate();
         $this->db->feeds->insert($item);
         DiscoUtils::log('Adding new metadata feed ' . tc_colored('INSERT', 'green') . ' ' . $item['id']);
     }
 }
示例#6
0
#!/usr/bin/env php
<?php 
require dirname(dirname(__FILE__)) . '/lib/autoload.php';
$command = new Commando\Command();
$command->option()->describedAs('Command to run: default is update.');
$command->option('cache-only')->boolean()->describedAs('Do not load metadata, only use existing cache.');
if ($command[0] === 'termcolor') {
    phpterm_demo();
    exit;
}
$backend = new FeideBackend();
if ($command['cache-only']) {
    DiscoUtils::log("Running in cache-only mode");
    $backend->enableCacheOnly(true);
}
DiscoUtils::log("DiscoJuice update script. Now updating feide feed.", true);
$backend->update();
示例#7
0
 public function getOverrides(&$data, $m)
 {
     $entityId = $m['entityid'];
     if (!isset($this->feedconfig)) {
         return;
     }
     if (!isset($this->feedconfig['overrides'])) {
         return;
     }
     if (!isset($this->feedconfig['overrides'][$entityId])) {
         return;
     }
     DiscoUtils::log('Processing overrides for entity ' . $entityId);
     foreach ($this->feedconfig['overrides'][$entityId] as $k => $v) {
         DiscoUtils::debug('Adding override for [' . $k . '] on entityId ' . $entityId);
         $data[$k] = $v;
     }
 }