aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xapp/DoctrineMigrations/Version20180405182455.php68
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php4
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php2
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php49
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/InstapaperImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/PinboardImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/ReadabilityImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php2
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php8
13 files changed, 132 insertions, 15 deletions
diff --git a/app/DoctrineMigrations/Version20180405182455.php b/app/DoctrineMigrations/Version20180405182455.php
new file mode 100755
index 00000000..71879c0e
--- /dev/null
+++ b/app/DoctrineMigrations/Version20180405182455.php
@@ -0,0 +1,68 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Schema\Schema;
7use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface;
9
10/**
11 * Add archived_at column and set its value to updated_at for is_archived entries.
12 */
13class Version20180405182455 extends AbstractMigration implements ContainerAwareInterface
14{
15 /**
16 * @var ContainerInterface
17 */
18 private $container;
19
20 public function setContainer(ContainerInterface $container = null)
21 {
22 $this->container = $container;
23 }
24
25 /**
26 * @param Schema $schema
27 */
28 public function up(Schema $schema)
29 {
30 $entryTable = $schema->getTable($this->getTable('entry'));
31
32 $this->skipIf($entryTable->hasColumn('archived_at'), 'It seems that you already played this migration.');
33
34 $entryTable->addColumn('archived_at', 'datetime', [
35 'notnull' => false,
36 ]);
37 }
38
39 public function postUp(Schema $schema)
40 {
41 $entryTable = $schema->getTable($this->getTable('entry'));
42 $this->skipIf(!$entryTable->hasColumn('archived_at'), 'Unable to add archived_at colum');
43
44 $this->connection->executeQuery(
45 'UPDATE ' . $this->getTable('entry') . ' SET archived_at = updated_at WHERE is_archived = :is_archived',
46 [
47 'is_archived' => true,
48 ]
49 );
50 }
51
52 /**
53 * @param Schema $schema
54 */
55 public function down(Schema $schema)
56 {
57 $entryTable = $schema->getTable($this->getTable('entry'));
58
59 $this->skipIf(!$entryTable->hasColumn('archived_at'), 'It seems that you already played this migration.');
60
61 $entryTable->dropColumn('archived_at');
62 }
63
64 private function getTable($tableName)
65 {
66 return $this->container->getParameter('database_table_prefix') . $tableName;
67 }
68}
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 0b4e74a0..dc63b98d 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -358,7 +358,7 @@ class EntryRestController extends WallabagRestController
358 } 358 }
359 359
360 if (null !== $data['isArchived']) { 360 if (null !== $data['isArchived']) {
361 $entry->setArchived((bool) $data['isArchived']); 361 $entry->updateArchived((bool) $data['isArchived']);
362 } 362 }
363 363
364 if (null !== $data['isStarred']) { 364 if (null !== $data['isStarred']) {
@@ -474,7 +474,7 @@ class EntryRestController extends WallabagRestController
474 } 474 }
475 475
476 if (null !== $data['isArchived']) { 476 if (null !== $data['isArchived']) {
477 $entry->setArchived((bool) $data['isArchived']); 477 $entry->updateArchived((bool) $data['isArchived']);
478 } 478 }
479 479
480 if (null !== $data['isStarred']) { 480 if (null !== $data['isStarred']) {
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
index 0e1510a2..62fb5fa6 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
@@ -98,7 +98,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
98 $entry6->setMimetype('text/html'); 98 $entry6->setMimetype('text/html');
99 $entry6->setTitle('test title entry6'); 99 $entry6->setTitle('test title entry6');
100 $entry6->setContent('This is my content /o/'); 100 $entry6->setContent('This is my content /o/');
101 $entry6->setArchived(true); 101 $entry6->updateArchived(true);
102 $entry6->setLanguage('de'); 102 $entry6->setLanguage('de');
103 $entry6->addTag($this->getReference('bar-tag')); 103 $entry6->addTag($this->getReference('bar-tag'));
104 104
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 2b1f2e05..b3cfdc4a 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -87,6 +87,15 @@ class Entry
87 private $isArchived = false; 87 private $isArchived = false;
88 88
89 /** 89 /**
90 * @var \DateTime
91 *
92 * @ORM\Column(name="archived_at", type="datetime", nullable=true)
93 *
94 * @Groups({"entries_for_user", "export_all"})
95 */
96 private $archivedAt = null;
97
98 /**
90 * @var bool 99 * @var bool
91 * 100 *
92 * @Exclude 101 * @Exclude
@@ -336,6 +345,44 @@ class Entry
336 } 345 }
337 346
338 /** 347 /**
348 * update isArchived and archive_at fields.
349 *
350 * @param bool $isArchived
351 *
352 * @return Entry
353 */
354 public function updateArchived($isArchived = false)
355 {
356 $this->setArchived($isArchived);
357 $this->setArchivedAt(null);
358 if ($this->isArchived()) {
359 $this->setArchivedAt(new \DateTime());
360 }
361
362 return $this;
363 }
364
365 /**
366 * @return \DateTime|null
367 */
368 public function getArchivedAt()
369 {
370 return $this->archivedAt;
371 }
372
373 /**
374 * @param \DateTime|null $archivedAt
375 *
376 * @return Entry
377 */
378 public function setArchivedAt($archivedAt = null)
379 {
380 $this->archivedAt = $archivedAt;
381
382 return $this;
383 }
384
385 /**
339 * Get isArchived. 386 * Get isArchived.
340 * 387 *
341 * @return bool 388 * @return bool
@@ -357,7 +404,7 @@ class Entry
357 404
358 public function toggleArchive() 405 public function toggleArchive()
359 { 406 {
360 $this->isArchived = $this->isArchived() ^ 1; 407 $this->updateArchived($this->isArchived() ^ 1);
361 408
362 return $this; 409 return $this;
363 } 410 }
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 225f1791..614386cb 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -133,7 +133,7 @@ abstract class BrowserImport extends AbstractImport
133 ); 133 );
134 } 134 }
135 135
136 $entry->setArchived($data['is_archived']); 136 $entry->updateArchived($data['is_archived']);
137 137
138 if (!empty($data['created_at'])) { 138 if (!empty($data['created_at'])) {
139 $dt = new \DateTime(); 139 $dt = new \DateTime();
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
index e4f0970c..e113ba00 100644
--- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php
+++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
@@ -135,7 +135,7 @@ class InstapaperImport extends AbstractImport
135 ); 135 );
136 } 136 }
137 137
138 $entry->setArchived($importedEntry['is_archived']); 138 $entry->updateArchived($importedEntry['is_archived']);
139 $entry->setStarred($importedEntry['is_starred']); 139 $entry->setStarred($importedEntry['is_starred']);
140 140
141 $this->em->persist($entry); 141 $this->em->persist($entry);
diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php
index 110b0464..9a5e8cb6 100644
--- a/src/Wallabag/ImportBundle/Import/PinboardImport.php
+++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php
@@ -119,7 +119,7 @@ class PinboardImport extends AbstractImport
119 ); 119 );
120 } 120 }
121 121
122 $entry->setArchived($data['is_archived']); 122 $entry->updateArchived($data['is_archived']);
123 $entry->setStarred($data['is_starred']); 123 $entry->setStarred($data['is_starred']);
124 $entry->setCreatedAt(new \DateTime($data['created_at'])); 124 $entry->setCreatedAt(new \DateTime($data['created_at']));
125 125
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index c1b35b7e..4b1ad1d7 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -194,7 +194,7 @@ class PocketImport extends AbstractImport
194 $this->fetchContent($entry, $url); 194 $this->fetchContent($entry, $url);
195 195
196 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted 196 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
197 $entry->setArchived(1 === $importedEntry['status'] || $this->markAsRead); 197 $entry->updateArchived(1 === $importedEntry['status'] || $this->markAsRead);
198 198
199 // 0 or 1 - 1 If the item is starred 199 // 0 or 1 - 1 If the item is starred
200 $entry->setStarred(1 === $importedEntry['favorite']); 200 $entry->setStarred(1 === $importedEntry['favorite']);
diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
index 002b27f4..d6777582 100644
--- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
+++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
@@ -111,7 +111,7 @@ class ReadabilityImport extends AbstractImport
111 // update entry with content (in case fetching failed, the given entry will be return) 111 // update entry with content (in case fetching failed, the given entry will be return)
112 $this->fetchContent($entry, $data['url'], $data); 112 $this->fetchContent($entry, $data['url'], $data);
113 113
114 $entry->setArchived($data['is_archived']); 114 $entry->updateArchived($data['is_archived']);
115 $entry->setStarred($data['is_starred']); 115 $entry->setStarred($data['is_starred']);
116 $entry->setCreatedAt(new \DateTime($data['created_at'])); 116 $entry->setCreatedAt(new \DateTime($data['created_at']));
117 117
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php
index c64ccd64..916137f1 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagImport.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php
@@ -122,7 +122,7 @@ abstract class WallabagImport extends AbstractImport
122 $entry->setPreviewPicture($importedEntry['preview_picture']); 122 $entry->setPreviewPicture($importedEntry['preview_picture']);
123 } 123 }
124 124
125 $entry->setArchived($data['is_archived']); 125 $entry->updateArchived($data['is_archived']);
126 $entry->setStarred($data['is_starred']); 126 $entry->setStarred($data['is_starred']);
127 127
128 if (!empty($data['created_at'])) { 128 if (!empty($data['created_at'])) {
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 58b617f3..6b26376d 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -438,6 +438,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
438 $this->assertSame(0, $content['is_archived']); 438 $this->assertSame(0, $content['is_archived']);
439 $this->assertSame(0, $content['is_starred']); 439 $this->assertSame(0, $content['is_starred']);
440 $this->assertNull($content['starred_at']); 440 $this->assertNull($content['starred_at']);
441 $this->assertNull($content['archived_at']);
441 $this->assertSame('New title for my article', $content['title']); 442 $this->assertSame('New title for my article', $content['title']);
442 $this->assertSame(1, $content['user_id']); 443 $this->assertSame(1, $content['user_id']);
443 $this->assertCount(2, $content['tags']); 444 $this->assertCount(2, $content['tags']);
@@ -533,6 +534,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
533 $this->assertSame(1, $content['is_archived']); 534 $this->assertSame(1, $content['is_archived']);
534 $this->assertSame(1, $content['is_starred']); 535 $this->assertSame(1, $content['is_starred']);
535 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); 536 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
537 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp());
536 $this->assertSame(1, $content['user_id']); 538 $this->assertSame(1, $content['user_id']);
537 } 539 }
538 540
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index e07c57dd..d709f4eb 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -849,7 +849,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
849 $entryArchived->setContent('Youhou'); 849 $entryArchived->setContent('Youhou');
850 $entryArchived->setTitle('Youhou'); 850 $entryArchived->setTitle('Youhou');
851 $entryArchived->addTag($tagArchived); 851 $entryArchived->addTag($tagArchived);
852 $entryArchived->setArchived(true); 852 $entryArchived->updateArchived(true);
853 $em->persist($entryArchived); 853 $em->persist($entryArchived);
854 854
855 $annotationArchived = new Annotation($user); 855 $annotationArchived = new Annotation($user);
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index bf0068b4..0ac119d8 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -621,7 +621,7 @@ class EntryControllerTest extends WallabagCoreTestCase
621 $content->setMimetype('text/html'); 621 $content->setMimetype('text/html');
622 $content->setTitle('test title entry'); 622 $content->setTitle('test title entry');
623 $content->setContent('This is my content /o/'); 623 $content->setContent('This is my content /o/');
624 $content->setArchived(true); 624 $content->updateArchived(true);
625 $content->setLanguage('fr'); 625 $content->setLanguage('fr');
626 626
627 $em->persist($content); 627 $em->persist($content);
@@ -774,7 +774,7 @@ class EntryControllerTest extends WallabagCoreTestCase
774 774
775 $entry = new Entry($this->getLoggedInUser()); 775 $entry = new Entry($this->getLoggedInUser());
776 $entry->setUrl($this->url); 776 $entry->setUrl($this->url);
777 $entry->setArchived(false); 777 $entry->updateArchived(false);
778 $this->getEntityManager()->persist($entry); 778 $this->getEntityManager()->persist($entry);
779 $this->getEntityManager()->flush(); 779 $this->getEntityManager()->flush();
780 780
@@ -1245,7 +1245,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1245 $entry = new Entry($this->getLoggedInUser()); 1245 $entry = new Entry($this->getLoggedInUser());
1246 $entry->setUrl('http://0.0.0.0/foo/baz/qux'); 1246 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1247 $entry->setTitle('Le manège'); 1247 $entry->setTitle('Le manège');
1248 $entry->setArchived(true); 1248 $entry->updateArchived(true);
1249 $this->getEntityManager()->persist($entry); 1249 $this->getEntityManager()->persist($entry);
1250 $this->getEntityManager()->flush(); 1250 $this->getEntityManager()->flush();
1251 1251
@@ -1275,7 +1275,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1275 $entry = new Entry($this->getLoggedInUser()); 1275 $entry = new Entry($this->getLoggedInUser());
1276 $entry->setUrl('http://domain/qux'); 1276 $entry->setUrl('http://domain/qux');
1277 $entry->setTitle('Le manège'); 1277 $entry->setTitle('Le manège');
1278 $entry->setArchived(true); 1278 $entry->updateArchived(true);
1279 $this->getEntityManager()->persist($entry); 1279 $this->getEntityManager()->persist($entry);
1280 $this->getEntityManager()->flush(); 1280 $this->getEntityManager()->flush();
1281 1281