public function previewAction()
 {
     $id = $this->params->get('id');
     $this->view->addLink = $this->view->qlink($this->translate('Run'), 'director/importsource/run', array('id' => $id));
     $source = ImportSource::load($id, $this->db());
     $this->prepareTabs($id)->activate('preview');
     $this->view->title = sprintf($this->translate('Import source preview: "%s"'), $source->source_name);
     $this->view->table = $this->applyPaginationLimits($this->loadTable('importsourceHook')->setConnection($this->db())->setImportSource($source));
     $this->render('list/table', null, true);
 }
Ejemplo n.º 2
0
 protected function getRowClasses($row)
 {
     if (!$this->revalidate) {
         return array();
     }
     try {
         $import = new Import(ImportSource::load($row->id, $this->connection()));
         if ($import->providesChanges()) {
             $row->source_name = sprintf('%s (%s)', $row->source_name, $this->view()->translate('has changes'));
             return 'pending-changes';
         } else {
             return 'in-sync';
         }
     } catch (Exception $e) {
         $row->source_name = $row->source_name . ' (' . $e->getMessage() . ')';
         return 'failing';
     }
 }
Ejemplo n.º 3
0
 protected function runScheduledImports()
 {
     foreach (ImportSource::loadAll($this->db()) as $source) {
         Benchmark::measure('Starting with import ' . $source->source_name);
         try {
             $import = new Import($source);
             if ($import->providesChanges()) {
                 printf('Import "%s" provides changes, triggering run... ', $source->source_name);
                 Benchmark::measure('Found changes for ' . $source->source_name);
                 if ($import->run()) {
                     Benchmark::measure('Import succeeded for ' . $source->source_name);
                     print "SUCCEEDED\n";
                 }
             }
         } catch (Exception $e) {
             echo $this->screen->colorize('ERROR: ' . $e->getMessage(), 'red') . "\n";
             Benchmark::measure('FAILED');
         }
     }
     return $this;
 }
Ejemplo n.º 4
0
 public function __construct(ImportSource $source)
 {
     $this->source = $source;
     $this->connection = $source->getConnection();
     $this->db = $this->connection->getDbAdapter();
 }
Ejemplo n.º 5
0
 protected function perpareImportSources($properties, $db)
 {
     $sources = array();
     foreach ($properties as $p) {
         $sourceId = $p->source_id;
         if (!array_key_exists($sourceId, $sources)) {
             $sources[$sourceId] = ImportSource::load($sourceId, $db);
         }
     }
     return $sources;
 }
Ejemplo n.º 6
0
 protected function getImportSource()
 {
     if ($this->importSource === null) {
         if ($this->hasObject()) {
             $src = ImportSource::load($this->object->source_id, $this->db);
         } else {
             $src = ImportSource::load($this->getSentValue('source_id'), $this->db);
         }
         $this->importSource = ImportSourceHook::loadByName($src->source_name, $this->db);
     }
     return $this->importSource;
 }