Esempio n. 1
0
 /**
  * ExcelReader constructor.
  * @param Configuration $config
  */
 public function __construct(Configuration $config)
 {
     $filename = $config->get(array('filename'));
     $header = $config->get(array('header'), false) ? 0 : null;
     $sheet = $config->get(array('sheet'), 0);
     parent::__construct(new \SplFileObject($filename), $header, $sheet);
 }
Esempio n. 2
0
 /**
  * @param Configuration $config
  * @throws \Exception
  */
 public function main(Configuration &$config)
 {
     $siteRoot = $config->get(array('task', 'siteRoot'), '');
     $fileDir = $config->get(array('task', 'fileDir'), '');
     if (empty($siteRoot)) {
         throw new \Exception('Task/Typo3/File: No site root defined.');
     }
     if (empty($fileDir)) {
         throw new \Exception('Task/Typo3/File: No file directory defined.');
     }
     // Empty data
     $this->data = [];
     // Trim slashes from paths
     $siteRoot = rtrim($siteRoot, '/');
     $fileDir = '/' . trim($fileDir, '/');
     // List files in the directory
     $files = new Directory($siteRoot . $fileDir);
     // Download files from remote server
     foreach ($files as $file) {
         // Connect to the file
         $identifier = $fileDir . '/' . $file->getFilename();
         // File is invalid
         if ($file->getSize() === 0) {
             continue;
         }
         // Update record info with typo3 sys_file compatible data
         $this->data[] = ['identifier' => $identifier, 'storage' => 1, 'identifier_hash' => sha1($identifier), 'folder_hash' => sha1($fileDir), 'extension' => $file->getExtension(), 'mime_type' => MimeType::get($file->getFilename()), 'name' => $file->getFilename(), 'sha1' => sha1_file($file->getRealPath()), 'size' => $file->getSize(), 'tstamp' => time(), 'last_indexed' => time(), 'creation_date' => $file->getCTime(), 'modification_date' => $file->getMTime()];
     }
 }
Esempio n. 3
0
 /**
  * DefaultTask constructor.
  * Crawl sources configuration and get data from those readers
  * @param Configuration $config
  */
 public function __construct(Configuration $config)
 {
     // Get sources
     $sources = $config->get(array('sources'), array());
     foreach ($sources as $key => $source) {
         // Skip this source if not defined
         if (!is_array($source) || empty($source)) {
             continue;
         }
         // Empty data array
         $data = array();
         // Create reader with source conf
         $reader = Migrator::createReader(new Configuration($source));
         // Writer will set data in an array
         $writer = new CallbackWriter(function ($item) use(&$data) {
             array_push($data, $item);
         });
         // Create new workflow
         $workflow = new Workflow($reader);
         $workflow->addWriter($writer);
         $workflow->process();
         // Apply data to sources
         $this->sources[$key] = $data;
     }
     if (count($this->sources) > 0) {
         $this->data = current($this->sources);
     }
     // Exec main with this task config
     $this->main($config->export());
 }
Esempio n. 4
0
 /**
  * CsvWriter constructor.
  * @param Configuration $config
  */
 public function __construct(Configuration $config)
 {
     $filename = $config->get(array('filename'));
     $delimiter = $config->get(array('delimiter'), ',');
     $enclosure = $config->get(array('enclosure'), '"');
     $utf8 = $config->get(array('utf8'), true);
     parent::__construct($delimiter, $enclosure, fopen($filename, 'w'), $utf8);
 }
Esempio n. 5
0
 /**
  * JsonReader constructor.
  * @param Configuration $config
  * @throws \Exception
  */
 public function __construct(Configuration $config)
 {
     $filename = $config->get(array('filename'));
     if ($filename == null) {
         throw new \Exception('Filename is not defined');
     }
     $this->data = json_decode(file_get_contents($filename));
 }
Esempio n. 6
0
 /**
  * CsvReader constructor.
  * @param Configuration $config
  * @throws \Exception
  */
 public function __construct(Configuration $config)
 {
     $filename = $config->get(array('filename'));
     $delimiter = $config->get(array('delimiter'), ',');
     $header = $config->get(array('header'), true);
     parent::__construct(new \SplFileObject($filename), $delimiter);
     if ($header) {
         $this->setHeaderRowNumber(0);
     }
 }
Esempio n. 7
0
 /**
  * JsonWriter constructor.
  * @param Configuration $config
  */
 public function __construct(Configuration $config)
 {
     parent::__construct();
     if ($config->get(array('pretty')) == true) {
         $this->options |= JSON_PRETTY_PRINT;
     }
     if ($config->get(array('unicode')) == true) {
         $this->options |= JSON_UNESCAPED_UNICODE;
     }
 }
Esempio n. 8
0
 /**
  * DbWriter constructor.
  * @param Configuration $config
  */
 public function __construct(Configuration $config)
 {
     $host = $config->get(array('host'), 'localhost');
     $dbname = $config->get(array('dbname'), '');
     $dbtype = $config->get(array('dbtype'), 'mysql');
     $username = $config->get(array('username'), 'root');
     $password = $config->get(array('password'), '');
     $table = $config->get(array('table'), '');
     $charset = $config->get(array('charset'), 'utf8');
     // Array containing fields that need to be checked to avoid duplicate data
     $this->uniqueFields = $config->get(array('unique'), array());
     // Create PDO object from config
     $pdo = new \PDO($dbtype . ':host=' . $host . ';dbname=' . $dbname . ';charset=' . $charset, $username, $password);
     // Set PDO error modes (for error output)
     $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
     parent::__construct($pdo, $table);
 }
Esempio n. 9
0
 /**
  * @param Configuration $config
  * @throws \Exception
  */
 public function main(Configuration $config)
 {
     $remote = $config->get(array('task', 'remote'), '');
     $local = $config->get(array('task', 'local'), '');
     $delay = $config->get(array('task', 'delay'), 0);
     if (empty($remote)) {
         throw new \Exception('Task/Sync: No remote path defined.');
     }
     if (empty($local)) {
         throw new \Exception('Task/Sync: No local path defined.');
     }
     if (count($this->sources) > 1) {
         throw new \Exception('Task/Sync: This task uses only 1 source.');
     }
     // Trim slashes from paths
     $remote = rtrim($remote, '/');
     $local = rtrim($local, '/');
     // Use only one source
     reset($this->sources);
     $source = current($this->sources);
     // Download files from remote server
     foreach ($source as $record) {
         usleep($delay);
         if (!array_key_exists('file', $record)) {
             throw new \Exception('Task/Sync: The record does not have a \'file\' field!');
         }
         // No file found
         if (empty($record['file'])) {
             continue;
         }
         try {
             $file = new File\Read($remote . '/' . $record['file']);
             $file->copy($local . '/' . $record['file']);
         } catch (\Exception $e) {
             // Can't read remote file
         }
     }
     exit;
 }
Esempio n. 10
0
 /**
  * PdoReader constructor.
  * @param Configuration $config
  * @throws \Exception
  */
 public function __construct(Configuration $config)
 {
     $host = $config->get(array('host'), 'localhost');
     $dbname = $config->get(array('dbname'), '');
     $dbtype = $config->get(array('dbtype'), 'mysql');
     $username = $config->get(array('username'), 'root');
     $password = $config->get(array('password'), '');
     $table = $config->get(array('table'), '');
     $query = $config->get(array('query'), '');
     if ($table . $query == '') {
         throw new \Exception('Table name is not defined');
     }
     if ($query == '') {
         $query = 'SELECT * FROM ' . $table;
     }
     $pdo = new \PDO($dbtype . ':host=' . $host . ';dbname=' . $dbname, $username, $password);
     parent::__construct($pdo, $query);
 }
Esempio n. 11
0
 /**
  * Create a Reader with given Configuration object
  * @param Configuration $config
  * @return mixed
  * @throws \Exception
  */
 public static function createReader(Configuration $config)
 {
     $name = $config->get(array('type'));
     return Migrator::summon(array('Reader', $name), $config);
 }