protected function getUpdateEvent($formData) { $changeEvent = new FeatureUpdateEvent($formData['id']); // Create and dispatch the change event $changeEvent->setLocale($formData["locale"])->setTitle($formData['title'])->setChapo($formData['chapo'])->setDescription($formData['description'])->setPostscriptum($formData['postscriptum']); return $changeEvent; }
/** * @param FeatureModel $feature * @depends testCreate */ public function testUpdate(FeatureModel $feature) { $event = new FeatureUpdateEvent($feature->getId()); $event->setLocale('en_US')->setTitle('test update')->setChapo('test chapo')->setDescription('test description')->setPostscriptum('test postscriptum')->setDispatcher($this->dispatcher); $action = new Feature(); $action->update($event); $updatedFeature = $event->getFeature(); $this->assertInstanceOf('Thelia\\Model\\Feature', $updatedFeature); $this->assertEquals('test update', $updatedFeature->getTitle()); $this->assertEquals('test chapo', $updatedFeature->getChapo()); $this->assertEquals('test description', $updatedFeature->getDescription()); $this->assertEquals('test postscriptum', $updatedFeature->getPostscriptum()); $this->assertEquals('en_US', $updatedFeature->getLocale()); return $updatedFeature; }
public function importFeatures() { $count = $errors = 0; $hdl = $this->t1db->query("select * from caracteristique order by classement"); while ($hdl && ($caracteristique = $this->t1db->fetch_object($hdl))) { $descs = $this->t1db->query_list("select * from caracteristiquedesc where caracteristique = ? order by lang asc", array($caracteristique->id)); $idx = 0; $event = new FeatureCreateEvent(); foreach ($descs as $desc) { try { $lang = $this->getT2Lang($desc->lang); if ($idx == 0) { $event->setLocale($lang->getLocale())->setTitle($desc->titre); $this->dispatcher->dispatch(TheliaEvents::FEATURE_CREATE, $event); // Updater position $update_position_event = new UpdatePositionEvent($event->getFeature()->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, $caracteristique->classement); $this->dispatcher->dispatch(TheliaEvents::FEATURE_UPDATE_POSITION, $update_position_event); Tlog::getInstance()->info("Created feature " . $event->getFeature()->getId() . " from {$desc->titre} ({$caracteristique->id})"); $this->feat_corresp->addEntry($caracteristique->id, $event->getFeature()->getId()); } $update_event = new FeatureUpdateEvent($event->getFeature()->getId()); $update_event->setLocale($lang->getLocale())->setTitle($desc->titre)->setChapo($desc->chapo)->setDescription($desc->description)->setPostscriptum(''); $this->dispatcher->dispatch(TheliaEvents::FEATURE_UPDATE, $update_event); $idx++; } catch (ImportException $ex) { Tlog::getInstance()->addError("Failed to create Feature from {$desc->titre} ({$caracteristique->id}): ", $ex->getMessage()); $errors++; } } $count++; } return new ImportChunkResult($count, $errors); }