Skip to content
Snippets Groups Projects
Commit 78e3fbe6 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

dev #48349 : version deletion

parent fc56d109
Branches
Tags
2 merge requests!2334Master,!2104Dev#48349 ux versionning
Pipeline #958 passed with stage
in 18 minutes and 10 seconds
......@@ -11,7 +11,11 @@ $user_formater = function($model, $attrib) {
$actions = [['url' => '/admin/cms/version/id/'. $this->article->getId() .'/key/%s',
'icon' => 'view',
'label' => $this->_('Voir')]];
'label' => $this->_('Voir')],
['url' => '/admin/cms/version-delete/id/'. $this->article->getId() .'/key/%s',
'icon' => 'delete',
'label' => $this->_('Supprimer'),
'anchorOptions' => ['onclick' => "return confirm('" . htmlspecialchars($this->_('Êtes-vous sur de vouloir supprimer cette version de l\\\'historique ?')) . "')"]]];
echo $this->tagModelTable($this->versions,
......
......@@ -82,4 +82,9 @@ class Class_Version extends Class_Entity {
public function callGetterByAttributeName($attribute) {
return $this->get($attribute);
}
public function delete() {
return static::getPersistence()->delete($this);
}
}
......@@ -135,6 +135,17 @@ class Class_Version_FilePersistence extends Class_Entity {
}
public function delete($version) {
if (!$version->getName() || !$version->getKey() || !$version->getId())
return;
$path = $this->_getFolderPath($version) . '/' . $version->getId() . '.json';
$file_system = $this->getFileSystem();
if ($file_system->file_exists($path))
$file_system->unlink($path);
}
public function encode($version) {
return json_encode($version->getData());
}
......
......@@ -70,6 +70,12 @@ class ZendAfi_Controller_Plugin_Versionning_Article
$this->_view->titre = $this->_('Versions de l\'article : "%s"',
$article->getTitre());
if (!$versions = $this->_versionFor($article)->findAll()) {
$this->_helper->notify($this->_('Aucune version dans l\'historique'));
$this->_redirect('admin/cms/edit/id/' . $article->getId());
return;
}
$this->_view->versions = $this->_versionFor($article)->findAll();
$this->_view->article = $article;
}
......@@ -85,7 +91,8 @@ class ZendAfi_Controller_Plugin_Versionning_Article
$key = $this->_versionFor($article)->findLastKey();
if (!$version = $this->_versionFor($article)->find($key)) {
$this->_redirectToIndex();
$this->_helper->notify($this->_('Aucune version dans l\'historique'));
$this->_redirectToEdit($article);
return;
}
......@@ -102,6 +109,24 @@ class ZendAfi_Controller_Plugin_Versionning_Article
}
public function versionDeleteAction() {
if (!$article = Class_Article::find((int)$this->_getParam('id'))) {
$this->_redirectToIndex();
return;
}
if (!$version = $this->_versionFor($article)->find($this->_getParam('key'))) {
$this->_helper->notify($this->_view->_('Version introuvable'));
$this->_redirectToEdit($article);
return;
}
$version->delete();
$this->_helper->notify($this->_view->_('Version supprimée'));
$this->_redirect('admin/cms/version/id/' . $article->getId());
}
public function notifyAfterSave($model) {
$this->_versionFor($model)
->setData($this->_getPost())
......@@ -109,6 +134,11 @@ class ZendAfi_Controller_Plugin_Versionning_Article
}
protected function _redirectToEdit($article) {
$this->_redirect('admin/cms/edit/id/' . $article->getId());
}
protected function _versionName() {
return 'article';
}
......
......@@ -49,7 +49,9 @@ class ZendAfi_View_Helper_Admin_RenderVersionForm
->_renderDefaultButtons($form,
[$this->_prevButton(),
$this->_nextButton(),
$this->_listButton($form)]);
$this->_deleteButton(),
$this->_listButton($form),
]);
}
......@@ -96,4 +98,20 @@ class ZendAfi_View_Helper_Admin_RenderVersionForm
'liste'),
['style' => 'filter: invert();'])));
}
protected function _deleteButton() {
$url = $this->view->url(['key' => $this->_version->getId(),
'action' => 'version-delete']);
$delete = (new Class_Entity())
->setText($this->_('Supprimer'))
->setUrl($url)
->setAttribs(['onclick' => "if (confirm('" . htmlspecialchars($this->_('Êtes-vous sur de vouloir supprimer cette version de l\\\'historique ?')) . "')) { window.location.href='" . $url ."'}; return false;"])
->setImage($this->view->tagImg(Class_Admin_Skin::current()
->renderIconUrlOn('buttons',
'remove')));
return $this->view->Button($delete);
}
}
\ No newline at end of file
......@@ -120,6 +120,12 @@ class VersionningArticleVersionsTest extends VersionningAdminTestCase {
}
/** @test */
public function firstVersionDeleteLinkShouldBePresent() {
$this->assertXPath('//table[@id="versions"]//tr[1]//td//a[contains(@href, "/cms/version-delete/id/27/key/2017-03-20_112408_33")]');
}
/** @test */
public function secondVersionAuthorShouldBeInconnu() {
$this->assertXPathContentContains('//table[@id="versions"]//tr[2]//td',
......@@ -201,6 +207,73 @@ class VersionningArticleVersionTest extends VersionningAdminTestCase {
public function articleAgendaShouldNotBeMarkedAsModified() {
$this->assertNotXPath('//tr[7][@class="modified"]');
}
/** @test */
public function previousButtonShouldBePresent() {
$this->assertXPathContentContains('//button[contains(@data-url, "/version/id/27/key/2017-03-19_103345_32")]',
'Précédente');
}
/** @test */
public function nextButtonShouldBePresentAndDisabled() {
$this->assertXPathContentContains('//button[@disabled]', 'Suivante');
}
/** @test */
public function listButtonShouldBePresent() {
$this->assertXPathContentContains('//button[contains(@data-url, "/versions/id/27")]',
'Liste complète');
}
/** @test */
public function deleteButtonShouldBePresent() {
$this->assertXPathContentContains('//button[contains(@data-url, "/version-delete/id/27/key/2017-03-20_112408_33")]',
'Supprimer');
}
}
class VersionningArticleVersionDeleteTest extends VersionningAdminTestCase {
protected $_file_deleted;
public function setUp() {
parent::setUp();
$this->_file_system->whenCalled('is_readable')->answers(true)
->whenCalled('scandir')
->answers(['.', '..',
'2017-03-20_112408_33.json'])
->whenCalled('file_get_contents')
->answers(json_encode(['titre' => 'An different title',
'debut' => '2016-12-23',
'fin' => '',
'events_debut' => '23/03/2017 16:00',
'events_fin' => '']))
->whenCalled('file_exists')->answers(true)
->whenCalled('unlink')
->willDo(function($path) { $this->_file_deleted = $path; });
;
$this->dispatch('/admin/cms/version-delete/id/27/key/2017-03-20_112408_33', true);
}
/** @test */
public function fileShouldBeDeleted() {
$this->assertContains('/temp/versions/article/27/2017-03-20_112408_33.json',
$this->_file_deleted);
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment