Ejemplo n.º 1
0
 public function __construct(Factory $factory)
 {
     $this->factory = $factory;
     $this->db = $factory->getDb();
     $this->logger = $factory->getLogger();
     $this->mainTable = $this->getMainTable();
     $this->relationsTable = $this->getRelationsTable();
     $this->createTables();
 }
Ejemplo n.º 2
0
 private function flushResults()
 {
     while ($this->mDb->more_results()) {
         $this->mDb->next_result();
         if ($res = $this->mDb->store_result()) {
             if ($res->errorno) {
                 Factory::getLogger()->error($res->error);
             }
             $res->free();
         }
     }
 }
Ejemplo n.º 3
0
 public function start()
 {
     $this->mPeeler->start();
     $this->mData = $this->mPeeler->getData();
     $c = $this->getConfig();
     foreach ($this->mData as &$sourceInfo) {
         if (preg_match('/' . $c['peeler']['url_metadata'] . '/', $sourceInfo['url'], $m) == 1) {
             $sourceInfo['metadata'] = Utils::purgeNumericSubscripts($m);
         } else {
             $log = Factory::getLogger();
             $log->error("Missing or unexpected information in url: %s", $sourceInfo['url']);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Run application.
  *
  * Starts application execution. Iterates through each enabled peeler,
  * creates the peeler object, passing in configuration data for
  * that peeler and runs it.
  *
  * @return void
  */
 public function run()
 {
     $log = Factory::getLogger();
     $log->message('Peel engine started');
     $this->mBase->run();
     $c = $this->getConfig();
     foreach ($c['peelers'] as $name => $peelerConf) {
         if ($peelerConf['peeler']['status'] == 'enabled') {
             $this->mPeelers[$name] = Factory::createPeeler($peelerConf);
             $this->mPeelers[$name]->start();
         }
     }
     $log->message('Peel engine finished');
 }
Ejemplo n.º 5
0
 private function getDestinationDir()
 {
     $c = $this->getConfig();
     $dir = $c['peeler']['download_to'];
     if (!file_exists($dir)) {
         $log = Factory::getLogger();
         $log->warning("Directory %s does not exist", $dir);
         if (mkdir($dir, 0777, true)) {
             $log->message("Destination directory successfully created");
         } else {
             $log->error("Could not create destination directory");
             $dir = FALSE;
         }
     }
     return $dir;
 }
Ejemplo n.º 6
0
 public function resolveDestinationPath($dir, $sourceInfo)
 {
     $log = Factory::getLogger();
     $res = $this->mPeeler->resolveDestinationPath($dir, $sourceInfo);
     $c = $this->getConfig();
     $db = Factory::getDatabase();
     switch ($c['peeler']['unique_by']) {
         case 'url':
             if ($db->urlDownloaded($sourceInfo['url'])) {
                 $log->message('Skipping %s (already downloaded)', $sourceInfo['url']);
                 $res = null;
             }
             break;
         case 'checksum':
             break;
     }
     return $res;
 }
Ejemplo n.º 7
0
 private function getJson()
 {
     switch ($_GET['json']) {
         case 'peel_log':
             $log = Factory::getLogger();
             $data = $log->getContent();
             break;
         case 'peel_ctrl':
             $conf = Factory::getConfig();
             $data = array_map(function ($e) {
                 return $e['peeler'];
             }, $conf['peelers']);
             break;
         default:
             $data = array();
     }
     return json_encode($data);
 }
Ejemplo n.º 8
0
 private function expand($metadata, $tag)
 {
     $exp = '';
     $parts = explode('|', $tag);
     if (isset($metadata[$parts[0]])) {
         $exp = trim($metadata[$parts[0]]);
         for ($i = 1; $i < count($parts); $i++) {
             $params = array();
             if (preg_match('/^([^\\(]+)\\(([^\\)]*)\\)$/i', $parts[$i], $m)) {
                 $func = $m[1];
                 $params = explode(',', $m[2]);
             } else {
                 $func = strtolower(trim($parts[$i]));
             }
             $exp = $this->execute($func, $params, $exp);
         }
     } else {
         $log = Factory::getLogger();
         $log->error("Missing %s in metadata", $tag);
     }
     return $exp;
 }
Ejemplo n.º 9
0
 /**
  * Enable available peeler.
  *
  * Copies the configuration file for the selected peeler from the
  * peelers-available directory to the peelers-enabled directory.
  *
  * @param string $peelerToEnable The name of the peeler that should be enabled.
  * @return void
  */
 private function enablePeeler($peelerToEnable)
 {
     if (empty($peelerToEnable)) {
         return;
     }
     $source = sprintf('%s/%s.conf', $this->mPathPeelersAvailable, $peelerToEnable);
     $destin = sprintf('%s/%s.conf', $this->mPathPeelersEnabled, $peelerToEnable);
     if (!file_exists($destin) && file_exists($source)) {
         if (symlink($source, $destin)) {
             Factory::getLogger()->message("Peeler %s successfully enabled", $peelerToEnable);
         } else {
             Factory::getLogger()->error("Unable to acitvate peeler %s", $peelerToEnable);
         }
     }
 }
Ejemplo n.º 10
0
 public function __construct($configKey, $apiUrl = '')
 {
     $this->setConfigKey($configKey);
     if ($apiUrl == '') {
         $apiUrl = getenv('sofortApiUrl') != '' ? getenv('sofortApiUrl') : self::GATEWAY_URL;
     }
     $SofortLibHttp = Factory::getHttpConnection($apiUrl);
     $XmlDataHandler = Factory::getDataHandler($configKey);
     $this->setDataHandler($XmlDataHandler);
     $FileLogger = Factory::getLogger();
     $this->setLogger($FileLogger);
     $this->_DataHandler->setConnection($SofortLibHttp);
     $this->enableLogging = getenv('sofortDebug') == 'true' ? true : false;
 }