Beispiel #1
0
 function init(Master $master, DBAL $adapter)
 {
     if (!$master->getJobs()->findByPk(array('id_job' => 0))) {
         $job = $master->create('job', array('name' => 'Scheduler', 'status' => 'A', 'system' => true));
         $job->save();
         $adapter->commit();
     }
 }
Beispiel #2
0
 protected function saveLinks(Master $master, $model, $pk, $data)
 {
     $schema = $this->schema;
     $data = get_object_vars($data);
     unset($pk['v_end']);
     $makeKey = function ($fields, $data) {
         $items = array();
         foreach ($fields as $field) {
             $items[] = $data[$field];
         }
         return implode(':', $items);
     };
     $convertPkForModel = function ($linkName, $pk) use($schema, $model) {
         $linkModel = $schema->getModel($linkName);
         $parentModel = $schema->getModel($model);
         $reference = $linkModel->getOutReference($parentModel->getName());
         $properties = $reference->getProperties();
         foreach ($properties as $property) {
             foreach ($pk as $key => $value) {
                 if ($key == $property->getForeignName()) {
                     unset($pk[$key]);
                     $pk[$property->getName()] = $value;
                 }
             }
         }
         return $pk;
     };
     foreach ($data as $linkName => $records) {
         $linkPk = $schema->getModel($linkName)->getPk();
         unset($linkPk[array_search('v_end', $linkPk)]);
         $repository = $master->getRepository($linkName);
         $existingLinks = $repository->findAll($convertPkForModel($linkName, $pk));
         $hash = array();
         foreach ($existingLinks as $existingLink) {
             $key = $makeKey($linkPk, $existingLink->asArray());
             $hash[$key] = $existingLink;
         }
         foreach ($records as $record) {
             $record = get_object_vars($record);
             $key = $makeKey($linkPk, $record);
             if (isset($hash[$key])) {
                 $existingLink = $hash[$key];
                 $existingLink->merge($record);
                 unset($hash[$key]);
             } else {
                 $existingLink = $repository->create($record);
             }
             $existingLink->save();
         }
         foreach ($hash as $key => $record) {
             $record->delete();
         }
     }
 }
Beispiel #3
0
 function init(Init $init, Master $master, DBAL $adapter)
 {
     $system = $master->getJobs()->findOne(array('system' => true));
     $now = $adapter->fetchNow();
     if ($system->getActiveTask()) {
         $message = sprintf("Task %s is running", $system->getActiveTask()->getIdTask());
         if ($this->createSystemFail) {
             $task = $system->createActiveTask()->setDtEnd($now)->setStatus('F')->save();
             $task->log($message);
         }
         throw new \Exception($message);
     }
     $task = $system->createActiveTask();
     $tasks = $master->getTasks()->findWhere('dt_scheduled < :now and status = :status', array('now' => $now, 'status' => 'N'));
     if (count($tasks)) {
         $task->log(sprintf('Found %s task(s).', count($tasks)));
         foreach ($tasks as $task) {
             //
         }
     } else {
         $task->log('No tasks found');
     }
     $task->setDtEnd($adapter->fetchNow(true))->setStatus('C')->save();
 }
Beispiel #4
0
 public function testMaster()
 {
     $personRepository = $this->master->getPersons();
     $this->assertNotNull($personRepository);
     $this->assertEquals("Storage\\Repository\\PersonRepository", get_class($personRepository));
 }