aboutsummaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authoradev <adev2000@gmail.com>2017-05-07 17:21:30 +0200
committeradev <adev2000@gmail.com>2017-06-04 11:38:29 +0200
commit2c3e148b0029a094431622feac79fafcd0d43fc8 (patch)
treef59d3d2088af87f3898b4c4de28639b70efbe4b4 /app
parenta687c8d915276eee0c0494156700f7d0c0606735 (diff)
downloadwallabag-2c3e148b0029a094431622feac79fafcd0d43fc8.tar.gz
wallabag-2c3e148b0029a094431622feac79fafcd0d43fc8.tar.zst
wallabag-2c3e148b0029a094431622feac79fafcd0d43fc8.zip
Displays an error with an annotation with a too long quote
Fix #2762
Diffstat (limited to 'app')
-rw-r--r--app/DoctrineMigrations/Version20170511211659.php100
-rw-r--r--app/Resources/static/themes/_global/index.js16
2 files changed, 115 insertions, 1 deletions
diff --git a/app/DoctrineMigrations/Version20170511211659.php b/app/DoctrineMigrations/Version20170511211659.php
new file mode 100644
index 00000000..d19b5ac5
--- /dev/null
+++ b/app/DoctrineMigrations/Version20170511211659.php
@@ -0,0 +1,100 @@
1<?php
2
3namespace Application\Migrations;
4
5use Doctrine\DBAL\Migrations\AbstractMigration;
6use Doctrine\DBAL\Migrations\SkipMigrationException;
7use Doctrine\DBAL\Schema\Schema;
8use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9use Symfony\Component\DependencyInjection\ContainerInterface;
10
11/**
12 * Increase the length of the "quote" column of "annotation" table
13 */
14class Version20170511211659 extends AbstractMigration implements ContainerAwareInterface
15{
16 /**
17 * @var ContainerInterface
18 */
19 private $container;
20
21 public function setContainer(ContainerInterface $container = null)
22 {
23 $this->container = $container;
24 }
25
26 private function getTable($tableName)
27 {
28 return $this->container->getParameter('database_table_prefix') . $tableName;
29 }
30
31 public function up(Schema $schema)
32 {
33 $tableName = $this->getTable('annotation');
34
35 switch ($this->connection->getDatabasePlatform()->getName()) {
36 case 'sqlite':
37 $this->addSql(<<<EOD
38CREATE TEMPORARY TABLE __temp__wallabag_annotation AS
39 SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
40 FROM ${tableName}
41EOD
42 );
43 $this->addSql('DROP TABLE ' . $tableName);
44 $this->addSql(<<<EOD
45CREATE TABLE ${tableName}
46(
47 id INTEGER PRIMARY KEY NOT NULL,
48 user_id INTEGER DEFAULT NULL,
49 entry_id INTEGER DEFAULT NULL,
50 text CLOB NOT NULL,
51 created_at DATETIME NOT NULL,
52 updated_at DATETIME NOT NULL,
53 quote CLOB NOT NULL,
54 ranges CLOB NOT NULL,
55 CONSTRAINT FK_A7AED006A76ED395 FOREIGN KEY (user_id) REFERENCES wallabag_user (id),
56 CONSTRAINT FK_A7AED006BA364942 FOREIGN KEY (entry_id) REFERENCES wallabag_entry (id) ON DELETE CASCADE
57);
58CREATE INDEX IDX_A7AED006A76ED395 ON wallabag_annotation (user_id);
59CREATE INDEX IDX_A7AED006BA364942 ON wallabag_annotation (entry_id);
60EOD
61 );
62
63 $this->addSql(<<<EOD
64INSERT INTO ${tableName} (id, user_id, entry_id, text, created_at, updated_at, quote, ranges)
65SELECT id, user_id, entry_id, text, created_at, updated_at, quote, ranges
66FROM __temp__wallabag_annotation;
67EOD
68 );
69 $this->addSql('DROP TABLE __temp__wallabag_annotation');
70 break;
71
72 case 'mysql':
73 $this->addSql('ALTER TABLE '.$tableName.' MODIFY quote TEXT NOT NULL');
74 break;
75
76 case 'postgresql':
77 $this->addSql('ALTER TABLE '.$tableName.' ALTER COLUMN quote TYPE TEXT NOT NULL ');
78 break;
79 }
80 }
81
82 public function down(Schema $schema)
83 {
84 $tableName = $this->getTable('annotation');
85
86 switch ($this->connection->getDatabasePlatform()->getName()) {
87 case 'sqlite':
88 throw new SkipMigrationException('Too complex ...');
89 break;
90
91 case 'mysql':
92 $this->addSql('ALTER TABLE '.$tableName.' MODIFY quote VARCHAR(255) NOT NULL');
93 break;
94
95 case 'postgresql':
96 $this->addSql('ALTER TABLE '.$tableName.' ALTER COLUMN quote TYPE VARCHAR(255) NOT NULL ');
97 break;
98 }
99 }
100}
diff --git a/app/Resources/static/themes/_global/index.js b/app/Resources/static/themes/_global/index.js
index 3fdcaa3d..3ec26488 100644
--- a/app/Resources/static/themes/_global/index.js
+++ b/app/Resources/static/themes/_global/index.js
@@ -34,7 +34,21 @@ $(document).ready(() => {
34 app.registry.registerUtility(authorization, 'authorizationPolicy'); 34 app.registry.registerUtility(authorization, 'authorizationPolicy');
35 35
36 const x = JSON.parse($('#annotationroutes').html()); 36 const x = JSON.parse($('#annotationroutes').html());
37 app.include(annotator.storage.http, x); 37 app.include(annotator.storage.http, $.extend({}, x, {
38 onError(msg, xhr) {
39 if (!Object.prototype.hasOwnProperty.call(xhr, 'responseJSON')) {
40 annotator.notification.banner('An error occurred', 'error');
41 return;
42 }
43 $.each(xhr.responseJSON.children, (k, v) => {
44 if (v.errors) {
45 $.each(v.errors, (n, errorText) => {
46 annotator.notification.banner(errorText, 'error');
47 });
48 }
49 });
50 },
51 }));
38 52
39 app.start().then(() => { 53 app.start().then(() => {
40 app.annotations.load({ entry: x.entryId }); 54 app.annotations.load({ entry: x.entryId });