--- /dev/null
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Add archived_at column and set its value to updated_at for is_archived entries.
+ */
+class Version20180405182455 extends AbstractMigration implements ContainerAwareInterface
+{
+ /**
+ * @var ContainerInterface
+ */
+ private $container;
+
+ public function setContainer(ContainerInterface $container = null)
+ {
+ $this->container = $container;
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function up(Schema $schema)
+ {
+ $entryTable = $schema->getTable($this->getTable('entry'));
+
+ $this->skipIf($entryTable->hasColumn('archived_at'), 'It seems that you already played this migration.');
+
+ $entryTable->addColumn('archived_at', 'datetime', [
+ 'notnull' => false,
+ ]);
+ }
+
+ public function postUp(Schema $schema)
+ {
+ $entryTable = $schema->getTable($this->getTable('entry'));
+ $this->skipIf(!$entryTable->hasColumn('archived_at'), 'Unable to add archived_at colum');
+
+ $this->connection->executeQuery(
+ 'UPDATE ' . $this->getTable('entry') . ' SET archived_at = updated_at WHERE is_archived = :is_archived',
+ [
+ 'is_archived' => true,
+ ]
+ );
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function down(Schema $schema)
+ {
+ $entryTable = $schema->getTable($this->getTable('entry'));
+
+ $this->skipIf(!$entryTable->hasColumn('archived_at'), 'It seems that you already played this migration.');
+
+ $entryTable->dropColumn('archived_at');
+ }
+
+ private function getTable($tableName)
+ {
+ return $this->container->getParameter('database_table_prefix') . $tableName;
+ }
+}
}
if (null !== $data['isArchived']) {
- $entry->setArchived((bool) $data['isArchived']);
+ $entry->updateArchived((bool) $data['isArchived']);
}
if (null !== $data['isStarred']) {
}
if (null !== $data['isArchived']) {
- $entry->setArchived((bool) $data['isArchived']);
+ $entry->updateArchived((bool) $data['isArchived']);
}
if (null !== $data['isStarred']) {
$entry6->setMimetype('text/html');
$entry6->setTitle('test title entry6');
$entry6->setContent('This is my content /o/');
- $entry6->setArchived(true);
+ $entry6->updateArchived(true);
$entry6->setLanguage('de');
$entry6->addTag($this->getReference('bar-tag'));
*/
private $isArchived = false;
+ /**
+ * @var \DateTime
+ *
+ * @ORM\Column(name="archived_at", type="datetime", nullable=true)
+ *
+ * @Groups({"entries_for_user", "export_all"})
+ */
+ private $archivedAt = null;
+
/**
* @var bool
*
return $this;
}
+ /**
+ * update isArchived and archive_at fields.
+ *
+ * @param bool $isArchived
+ *
+ * @return Entry
+ */
+ public function updateArchived($isArchived = false)
+ {
+ $this->setArchived($isArchived);
+ $this->setArchivedAt(null);
+ if ($this->isArchived()) {
+ $this->setArchivedAt(new \DateTime());
+ }
+
+ return $this;
+ }
+
+ /**
+ * @return \DateTime|null
+ */
+ public function getArchivedAt()
+ {
+ return $this->archivedAt;
+ }
+
+ /**
+ * @param \DateTime|null $archivedAt
+ *
+ * @return Entry
+ */
+ public function setArchivedAt($archivedAt = null)
+ {
+ $this->archivedAt = $archivedAt;
+
+ return $this;
+ }
+
/**
* Get isArchived.
*
public function toggleArchive()
{
- $this->isArchived = $this->isArchived() ^ 1;
+ $this->updateArchived($this->isArchived() ^ 1);
return $this;
}
);
}
- $entry->setArchived($data['is_archived']);
+ $entry->updateArchived($data['is_archived']);
if (!empty($data['created_at'])) {
$dt = new \DateTime();
);
}
- $entry->setArchived($importedEntry['is_archived']);
+ $entry->updateArchived($importedEntry['is_archived']);
$entry->setStarred($importedEntry['is_starred']);
$this->em->persist($entry);
);
}
- $entry->setArchived($data['is_archived']);
+ $entry->updateArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);
$entry->setCreatedAt(new \DateTime($data['created_at']));
$this->fetchContent($entry, $url);
// 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
- $entry->setArchived(1 === $importedEntry['status'] || $this->markAsRead);
+ $entry->updateArchived(1 === $importedEntry['status'] || $this->markAsRead);
// 0 or 1 - 1 If the item is starred
$entry->setStarred(1 === $importedEntry['favorite']);
// update entry with content (in case fetching failed, the given entry will be return)
$this->fetchContent($entry, $data['url'], $data);
- $entry->setArchived($data['is_archived']);
+ $entry->updateArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);
$entry->setCreatedAt(new \DateTime($data['created_at']));
$entry->setPreviewPicture($importedEntry['preview_picture']);
}
- $entry->setArchived($data['is_archived']);
+ $entry->updateArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);
if (!empty($data['created_at'])) {
$this->assertSame(0, $content['is_archived']);
$this->assertSame(0, $content['is_starred']);
$this->assertNull($content['starred_at']);
+ $this->assertNull($content['archived_at']);
$this->assertSame('New title for my article', $content['title']);
$this->assertSame(1, $content['user_id']);
$this->assertCount(2, $content['tags']);
$this->assertSame(1, $content['is_archived']);
$this->assertSame(1, $content['is_starred']);
$this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
+ $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp());
$this->assertSame(1, $content['user_id']);
}
$entryArchived->setContent('Youhou');
$entryArchived->setTitle('Youhou');
$entryArchived->addTag($tagArchived);
- $entryArchived->setArchived(true);
+ $entryArchived->updateArchived(true);
$em->persist($entryArchived);
$annotationArchived = new Annotation($user);
$content->setMimetype('text/html');
$content->setTitle('test title entry');
$content->setContent('This is my content /o/');
- $content->setArchived(true);
+ $content->updateArchived(true);
$content->setLanguage('fr');
$em->persist($content);
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url);
- $entry->setArchived(false);
+ $entry->updateArchived(false);
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl('http://0.0.0.0/foo/baz/qux');
$entry->setTitle('Le manège');
- $entry->setArchived(true);
+ $entry->updateArchived(true);
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl('http://domain/qux');
$entry->setTitle('Le manège');
- $entry->setArchived(true);
+ $entry->updateArchived(true);
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();