/** * Pubblish atto albo: TODO: update pubblicare to 1, assign progressivo number * * @return string */ public function publishAction() { if ($this->getServiceLocator()->get('request')->isPost()) { $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $userDetails = $this->recoverUserDetails(); $id = $this->params()->fromPost('publishId'); $helper = new AlboPretorioControllerHelper(); $helper->setConnection($em->getConnection()); $helper->getConnection()->beginTransaction(); try { $attoRecord = $helper->recoverWrapperRecordsById(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), array('id' => $id, 'limit' => 1), $id); $helper->checkRecords($attoRecord, 'Dati atto non trovati'); $numeroProgressivo = $helper->recoverNumeroProgressivo(new AlboPretorioArticoliGetterWrapper(new AlboPretorioArticoliGetter($em)), $attoRecord[0]['anno']); $helper->publishArticle($id, $numeroProgressivo); $helper->getConnection()->commit(); $this->log(array('user_id' => $userDetails->id, 'message' => "Pubblicato atto albo pretorio " . $attoRecord[0]['titolo'], 'type' => 'info', 'backend' => 1, 'module_id' => ModulesContainer::albo_pretorio_id, 'reference_id' => $attoRecord[0]['id'])); } catch (\Exception $e) { try { $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $exDb) { } $this->log(array('user_id' => $userDetails->id, 'message' => "Errore pubblicazione atto albo pretorio " . $attoRecord[0]['titolo'] . ' Messaggio generato: ' . $e->getMessage(), 'type' => 'error', 'backend' => 1, 'module_id' => ModulesContainer::albo_pretorio_id, 'reference_id' => $attoRecord[0]['id'])); // TODO: redirect to a message page and show an error message } } return $this->redirectToSummary(); }
public function testPublishArticle() { $this->helper->setConnection($this->getConnectionMock()); $this->assertEquals($this->helper->publishArticle(1, 1), 1); }