From 74b7c0985d3ff2b2011d0809c9b71e505e9aa947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 14 Dec 2016 09:47:07 +0100 Subject: Added index on entry.uuid Useful for entry sharing --- app/DoctrineMigrations/Version20161214094403.php | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 app/DoctrineMigrations/Version20161214094403.php diff --git a/app/DoctrineMigrations/Version20161214094403.php b/app/DoctrineMigrations/Version20161214094403.php new file mode 100644 index 00000000..fc9acb5a --- /dev/null +++ b/app/DoctrineMigrations/Version20161214094403.php @@ -0,0 +1,53 @@ +container = $container; + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix').$tableName; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + $this->skipIf($entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.'); + + $entryTable->addIndex(['uuid'], $this->indexName); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + $this->skipIf(false === $entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.'); + + $entryTable->dropIndex($this->indexName); + } +} -- cgit v1.2.3 From af131cb513584a2bbc992dfcaa756a5b425dbe50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 14 Dec 2016 10:11:33 +0100 Subject: Added index on table creation --- src/Wallabag/CoreBundle/Entity/Entry.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 3ae5334f..8dcc7190 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -22,7 +22,8 @@ use Wallabag\AnnotationBundle\Entity\Annotation; * @ORM\Table( * name="`entry`", * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, - * indexes={@ORM\Index(name="created_at", columns={"created_at"})} + * indexes={@ORM\Index(name="created_at", columns={"created_at"})}, + * indexes={@ORM\Index(name="uuid", columns={"uuid"})} * ) * @ORM\HasLifecycleCallbacks() * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") -- cgit v1.2.3 From 8137515171a9b3c8e7c3720958acfdccb96803f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 18 Dec 2016 14:09:56 +0100 Subject: Fixed index on entry.uuid and changed uuid field type --- .travis.yml | 4 +++- src/Wallabag/CoreBundle/Controller/EntryController.php | 3 +++ src/Wallabag/CoreBundle/Entity/Entry.php | 8 +++++--- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c8093bf..7468b116 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,13 +5,14 @@ services: - redis # faster builds on docker-container setup -sudo: false +sudo: required # used for HHVM addons: apt: packages: - tidy + postgresql: 9.5 # cache vendor dirs cache: @@ -59,6 +60,7 @@ before_script: - if [[ ! $PHP = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi - composer self-update --no-progress - if [[ $DB = pgsql ]]; then psql -c 'create database wallabag_test;' -U postgres; fi; + - if [[ $DB = pgsql ]]; then psql -U postgres wallabag_test -c 'create extension "uuid-ossp";'; fi; install: - if [[ $ASSETS = build ]]; then source ~/.nvm/nvm.sh && nvm install 6.7; fi; diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index b03f49ed..83148671 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -355,6 +355,9 @@ class EntryController extends Controller { $this->checkUserAction($entry); + $version = $this->getDoctrine()->getManager()->getConnection()->query('SELECT version();')->fetchColumn(); + var_dump($version); + return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 8dcc7190..4c22cf9c 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -22,8 +22,10 @@ use Wallabag\AnnotationBundle\Entity\Annotation; * @ORM\Table( * name="`entry`", * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, - * indexes={@ORM\Index(name="created_at", columns={"created_at"})}, - * indexes={@ORM\Index(name="uuid", columns={"uuid"})} + * indexes={ + * @ORM\Index(name="created_at", columns={"created_at"}), + * @ORM\Index(name="uuid", columns={"uuid"}) + * } * ) * @ORM\HasLifecycleCallbacks() * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") @@ -45,7 +47,7 @@ class Entry /** * @var string * - * @ORM\Column(name="uuid", type="text", nullable=true) + * @ORM\Column(name="uuid", type="guid", nullable=true) * * @Groups({"entries_for_user", "export_all"}) */ diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index c347cca5..10cda475 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -816,6 +816,7 @@ class EntryControllerTest extends WallabagCoreTestCase // generating the uuid $client->request('GET', '/share/'.$content->getId()); + var_dump($client->getResponse()->getContent()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); // follow link with uuid -- cgit v1.2.3 From 89cd670abfc77ca268a538c9323a4026fec06fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Dec 2016 09:49:22 +0100 Subject: Changed uuid type in database --- .travis.yml | 4 +--- Makefile | 3 +-- app/DoctrineMigrations/Version20160410190541.php | 3 ++- src/Wallabag/CoreBundle/Controller/EntryController.php | 3 --- src/Wallabag/CoreBundle/Entity/Entry.php | 2 +- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 1 - 6 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7468b116..8c8093bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,14 +5,13 @@ services: - redis # faster builds on docker-container setup -sudo: required +sudo: false # used for HHVM addons: apt: packages: - tidy - postgresql: 9.5 # cache vendor dirs cache: @@ -60,7 +59,6 @@ before_script: - if [[ ! $PHP = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi - composer self-update --no-progress - if [[ $DB = pgsql ]]; then psql -c 'create database wallabag_test;' -U postgres; fi; - - if [[ $DB = pgsql ]]; then psql -U postgres wallabag_test -c 'create extension "uuid-ossp";'; fi; install: - if [[ $ASSETS = build ]]; then source ~/.nvm/nvm.sh && nvm install 6.7; fi; diff --git a/Makefile b/Makefile index 83c5f37a..b3335261 100755 --- a/Makefile +++ b/Makefile @@ -27,8 +27,7 @@ build: ## Run grunt @grunt test: ## Launch wallabag testsuite - @if [ ! -d "vendor/phpunit" ]; then composer install; fi - @ant prepare && vendor/phpunit/phpunit/phpunit -v + @ant prepare && bin/simple-phpunit -v release: ## Create a package. Need a VERSION parameter (eg: `make release VERSION=master`). ifndef VERSION diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index 0cdec008..8761a9bb 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -33,8 +33,9 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI $this->skipIf($entryTable->hasColumn('uuid'), 'It seems that you already played this migration.'); - $entryTable->addColumn('uuid', 'guid', [ + $entryTable->addColumn('uuid', 'string', [ 'notnull' => false, + 'length' => 23, ]); $this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_public', '1', 'entry')"); } diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 83148671..b03f49ed 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -355,9 +355,6 @@ class EntryController extends Controller { $this->checkUserAction($entry); - $version = $this->getDoctrine()->getManager()->getConnection()->query('SELECT version();')->fetchColumn(); - var_dump($version); - return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 4c22cf9c..4c9d518f 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -47,7 +47,7 @@ class Entry /** * @var string * - * @ORM\Column(name="uuid", type="guid", nullable=true) + * @ORM\Column(name="uuid", type="string", length=23, nullable=true) * * @Groups({"entries_for_user", "export_all"}) */ diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 10cda475..c347cca5 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -816,7 +816,6 @@ class EntryControllerTest extends WallabagCoreTestCase // generating the uuid $client->request('GET', '/share/'.$content->getId()); - var_dump($client->getResponse()->getContent()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); // follow link with uuid -- cgit v1.2.3 From 7239082a5e290dada1d393f7a25acebb09ace2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 29 Dec 2016 10:09:44 +0100 Subject: Renamed uuid to uid --- app/DoctrineMigrations/Version20160410190541.php | 6 ++--- app/DoctrineMigrations/Version20161214094403.php | 6 ++--- .../CoreBundle/Controller/EntryController.php | 10 ++++----- src/Wallabag/CoreBundle/Entity/Entry.php | 26 +++++++++++----------- .../CoreBundle/Controller/EntryControllerTest.php | 12 +++++----- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/DoctrineMigrations/Version20160410190541.php b/app/DoctrineMigrations/Version20160410190541.php index 8761a9bb..f166a325 100644 --- a/app/DoctrineMigrations/Version20160410190541.php +++ b/app/DoctrineMigrations/Version20160410190541.php @@ -31,9 +31,9 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI { $entryTable = $schema->getTable($this->getTable('entry')); - $this->skipIf($entryTable->hasColumn('uuid'), 'It seems that you already played this migration.'); + $this->skipIf($entryTable->hasColumn('uid'), 'It seems that you already played this migration.'); - $entryTable->addColumn('uuid', 'string', [ + $entryTable->addColumn('uid', 'string', [ 'notnull' => false, 'length' => 23, ]); @@ -46,7 +46,7 @@ class Version20160410190541 extends AbstractMigration implements ContainerAwareI public function down(Schema $schema) { $entryTable = $schema->getTable($this->getTable('entry')); - $entryTable->dropColumn('uuid'); + $entryTable->dropColumn('uid'); $this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'"); } diff --git a/app/DoctrineMigrations/Version20161214094403.php b/app/DoctrineMigrations/Version20161214094403.php index fc9acb5a..5948b5fa 100644 --- a/app/DoctrineMigrations/Version20161214094403.php +++ b/app/DoctrineMigrations/Version20161214094403.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Added index on wallabag_entry.uuid + * Added index on wallabag_entry.uid */ class Version20161214094403 extends AbstractMigration implements ContainerAwareInterface { @@ -17,7 +17,7 @@ class Version20161214094403 extends AbstractMigration implements ContainerAwareI */ private $container; - private $indexName = 'IDX_entry_uiid'; + private $indexName = 'IDX_entry_uid'; public function setContainer(ContainerInterface $container = null) { @@ -37,7 +37,7 @@ class Version20161214094403 extends AbstractMigration implements ContainerAwareI $entryTable = $schema->getTable($this->getTable('entry')); $this->skipIf($entryTable->hasIndex($this->indexName), 'It seems that you already played this migration.'); - $entryTable->addIndex(['uuid'], $this->indexName); + $entryTable->addIndex(['uid'], $this->indexName); } /** diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index b03f49ed..f7398e69 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -539,8 +539,8 @@ class EntryController extends Controller { $this->checkUserAction($entry); - if (null === $entry->getUuid()) { - $entry->generateUuid(); + if (null === $entry->getUid()) { + $entry->generateUid(); $em = $this->getDoctrine()->getManager(); $em->persist($entry); @@ -548,7 +548,7 @@ class EntryController extends Controller } return $this->redirect($this->generateUrl('share_entry', [ - 'uuid' => $entry->getUuid(), + 'uid' => $entry->getUid(), ])); } @@ -565,7 +565,7 @@ class EntryController extends Controller { $this->checkUserAction($entry); - $entry->cleanUuid(); + $entry->cleanUid(); $em = $this->getDoctrine()->getManager(); $em->persist($entry); @@ -581,7 +581,7 @@ class EntryController extends Controller * * @param Entry $entry * - * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") + * @Route("/share/{uid}", requirements={"uid" = ".+"}, name="share_entry") * @Cache(maxage="25200", smaxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 4c9d518f..7276b437 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -24,7 +24,7 @@ use Wallabag\AnnotationBundle\Entity\Annotation; * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, * indexes={ * @ORM\Index(name="created_at", columns={"created_at"}), - * @ORM\Index(name="uuid", columns={"uuid"}) + * @ORM\Index(name="uid", columns={"uid"}) * } * ) * @ORM\HasLifecycleCallbacks() @@ -47,11 +47,11 @@ class Entry /** * @var string * - * @ORM\Column(name="uuid", type="string", length=23, nullable=true) + * @ORM\Column(name="uid", type="string", length=23, nullable=true) * * @Groups({"entries_for_user", "export_all"}) */ - private $uuid; + private $uid; /** * @var string @@ -652,34 +652,34 @@ class Entry /** * @return string */ - public function getUuid() + public function getUid() { - return $this->uuid; + return $this->uid; } /** - * @param string $uuid + * @param string $uid * * @return Entry */ - public function setUuid($uuid) + public function setUid($uid) { - $this->uuid = $uuid; + $this->uid = $uid; return $this; } - public function generateUuid() + public function generateUid() { - if (null === $this->uuid) { + if (null === $this->uid) { // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter - $this->uuid = uniqid('', true); + $this->uid = uniqid('', true); } } - public function cleanUuid() + public function cleanUid() { - $this->uuid = null; + $this->uid = null; } /** diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index c347cca5..06ed2db6 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -810,15 +810,15 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneByUser($this->getLoggedInUserId()); - // no uuid - $client->request('GET', '/share/'.$content->getUuid()); + // no uid + $client->request('GET', '/share/'.$content->getUid()); $this->assertEquals(404, $client->getResponse()->getStatusCode()); - // generating the uuid + // generating the uid $client->request('GET', '/share/'.$content->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - // follow link with uuid + // follow link with uid $crawler = $client->followRedirect(); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); @@ -832,7 +832,7 @@ class EntryControllerTest extends WallabagCoreTestCase // sharing is now disabled $client->getContainer()->get('craue_config')->set('share_public', 0); - $client->request('GET', '/share/'.$content->getUuid()); + $client->request('GET', '/share/'.$content->getUid()); $this->assertEquals(404, $client->getResponse()->getStatusCode()); $client->request('GET', '/view/'.$content->getId()); @@ -843,7 +843,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); // share is now disable - $client->request('GET', '/share/'.$content->getUuid()); + $client->request('GET', '/share/'.$content->getUid()); $this->assertEquals(404, $client->getResponse()->getStatusCode()); } -- cgit v1.2.3