/** * Dodaje szablon do bazy szablonow * * Jezeli juz istnieje szablon o zadanej nazwie, porownuje hash md5 nowej tresci z hashem md5 ostatniej wersji * szablonu z baza. Jezeli sie roznia, dodaje $content jako najnowsza wersje szablonu o $this->_name. * Jezeli szablon o zadanej nazwie nie istnieje, dodaje $content jako nowy szablon. * * @param string $content * @param mixed $attachments * @throws Logic_WebService_Element_Template_Exception * @return Logic_WebService_Element_Template_Abstract */ public function addTemplate($content, $attachments = null) { $insert = array('ws_client_id' => $this->_ownerID, 'template_name' => $this->_name, 'template_content' => $content, 'template_content_hash' => md5($content)); $newest = $this->_model->getTemplateNewestByNameAndOwner($this->_name, $this->_ownerID); if ($newest) { // dodaje nowa wersje juz istniejacej templatki if (md5($content) == $newest->template_content_hash) { // throw new Logic_WebService_Element_Template_Exception('Zawartosc szablonu nie zmienila sie - aktualna wersja: ' . $newest->template_name . ' v.' . $newest->version_num . ' ' . $newest->created_at, 443); // zakomentowano 9.12.2010 // drobny ficzer ;] $this->addMessage('Zawartosc szablonu nie zmienila sie - aktualna wersja: ' . $newest->template_name . ' v.' . $newest->version_num . ' ' . $newest->created_at); $this->setHash(md5($content)); return $this; } else { $insert['version_num'] = $newest->version_num + 1; } } $this->_id = $this->_model->addTemplate($insert); $this->_content = $content; if ($attachments) { $model = new WsTemplateAttachment(); $attachmentsCheck = $attachments->getAttachments(); $hashesCheck = $attachments->getHashes(); if (empty($attachmentsCheck) && !empty($hashesCheck)) { throw new Logic_WebService_Exception('Podano hash\'e MD5 zamiast zalacznikow', 448); } $model->addAttachment($this->_id, $attachments->mapToModel()); } return $this; }
/** * Nowa wersja juz istniejacej templatki * * @return void */ public function addversionAction() { $request = $this->getRequest(); $id = $this->_helper->IdConvert->hexToStr($request->getParam('id')); $form = new Logic_Ws_Template_Form_NewVersion(); if ($request->isPost()) { if ($form->isCancelled($this->getRequest()->getPost())) { $this->_helper->redirector('index', null, null); return; } elseif ($form->isValid($request->getPost())) { try { $values = $form->getValues(); $newest = $this->_model->getTemplateNewest($values['template_name']); if ($newest->template_content_hash == md5($values['template_content'])) { $this->_helper->messenger->error('Zawartość templatki nie zmieniła się'); return; } $values['ws_client_id'] = $newest->ws_client_id; $values['template_content_hash'] = md5($values['template_content']); $values['version_num'] = $newest->version_num + 1; $this->_model->addTemplate($values); $this->_helper->messenger->success(); $this->_helper->redirector('index'); return; } catch (Logic_Ws_Exception $e) { $this->_helper->messenger->error(); } } } else { $data = array(); try { $data = $this->_model->getTemplateWithOwner($id); $newest = $this->_model->getTemplateNewest($data->template_name); if ($data->version_num < $newest->version_num) { $this->_helper->messenger->error('Ta templatka ma już nowszą wersję'); $this->_helper->redirector('index'); return; } } catch (Zend_Db_Exception $e) { $this->_helper->messenger->error(); $this->_helper->redirector('index'); return; } $form->setDefaults($data->toArray()); } $this->view->form = $form; }