]> git.agnieray.net Git - galette.git/commitdiff
Handle sequence on PostgreSQL for Texts; refs #1374 refs #1158
authorJohan Cwiklinski <jcwiklinski@teclib.com>
Sat, 18 Jan 2020 08:22:44 +0000 (09:22 +0100)
committerJohan Cwiklinski <jcwiklinski@teclib.com>
Sat, 18 Jan 2020 14:26:36 +0000 (15:26 +0100)
galette/includes/galette.inc.php
galette/install/scripts/mysql.sql
galette/install/scripts/pgsql.sql
galette/install/scripts/upgrade-to-0.931-mysql.sql [new file with mode: 0644]
galette/install/scripts/upgrade-to-0.931-pgsql.sql [new file with mode: 0644]
galette/lib/Galette/Core/Preferences.php
galette/lib/Galette/Entity/Texts.php
tests/Galette/Core/tests/units/Install.php
tests/Galette/Entity/tests/units/Texts.php [new file with mode: 0644]

index ea182814fa0ba59272c70fc6a39e19bdd180d053..acd9bdcd243a34fccc5d2267244415fbac938d27 100644 (file)
@@ -106,7 +106,7 @@ if (defined('GALETTE_XHPROF_PATH')
 
 define('GALETTE_VERSION', 'v0.9.3');
 define('GALETTE_COMPAT_VERSION', '0.9.2');
-define('GALETTE_DB_VERSION', '0.930');
+define('GALETTE_DB_VERSION', '0.931');
 if (!defined('GALETTE_MODE')) {
     define('GALETTE_MODE', 'PROD'); //DEV, PROD, MAINT or DEMO
 }
index 511d5f92c365fc1cc5b4265236f37be0dfc9e443..8edb1fe4f543750122233aed12d2a9f1d819dc9b 100644 (file)
@@ -333,6 +333,6 @@ DROP TABLE IF EXISTS galette_database;
 CREATE TABLE galette_database (
   version DECIMAL(4,3) NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-INSERT INTO galette_database(version) VALUES(0.93);
+INSERT INTO galette_database(version) VALUES(0.931);
 
 SET FOREIGN_KEY_CHECKS=1;
index 0c278c0eec9eb15c21f20030c90adf09644841e2..55199cbe2e5c15306ad4586ba394d375aa9a320c 100644 (file)
@@ -146,6 +146,15 @@ CREATE SEQUENCE galette_searches_id_seq
     MINVALUE 1
     CACHE 1;
 
+-- sequence for texts
+DROP SEQUENCE IF EXISTS galette_texts_id_seq;
+CREATE SEQUENCE galette_texts_id_seq
+    START 1
+    INCREMENT 1
+    MAXVALUE 2147483647
+    MINVALUE 1
+    CACHE 1;
+
 -- Schema
 -- REMINDER: Create order IS important, dependencies first !!
 DROP TABLE IF EXISTS galette_statuts CASCADE;
@@ -454,4 +463,4 @@ DROP TABLE IF EXISTS galette_database;
 CREATE TABLE galette_database (
   version decimal NOT NULL
 );
-INSERT INTO galette_database (version) VALUES(0.93);
+INSERT INTO galette_database (version) VALUES(0.931);
diff --git a/galette/install/scripts/upgrade-to-0.931-mysql.sql b/galette/install/scripts/upgrade-to-0.931-mysql.sql
new file mode 100644 (file)
index 0000000..592a3e8
--- /dev/null
@@ -0,0 +1,4 @@
+SET FOREIGN_KEY_CHECKS=0;
+
+UPDATE galette_database SET version = 0.931;
+SET FOREIGN_KEY_CHECKS=1;
diff --git a/galette/install/scripts/upgrade-to-0.931-pgsql.sql b/galette/install/scripts/upgrade-to-0.931-pgsql.sql
new file mode 100644 (file)
index 0000000..9671644
--- /dev/null
@@ -0,0 +1,10 @@
+-- sequence for texts
+DROP SEQUENCE IF EXISTS galette_texts_id_seq;
+CREATE SEQUENCE galette_texts_id_seq
+    START 1
+    INCREMENT 1
+    MAXVALUE 2147483647
+    MINVALUE 1
+    CACHE 1;
+
+UPDATE galette_database SET version = 0.931;
index ca6fc8f323686a265199894f22c6ffade8457c75..1931f132fdd7b0ed9e655f8d5ed38edfd190b7fb 100644 (file)
@@ -26,7 +26,6 @@
  *
  * @category  Core
  * @package   Galette
- *
  * @author    Johan Cwiklinski <johan@x-tnd.be>
  * @copyright 2007-2014 The Galette Team
  * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
index a622c733995de53b15cbb89485790add7603615f..bc5a8251eb6b67cdd9dddd49af5b334a08510c3e 100644 (file)
@@ -375,6 +375,11 @@ class Texts
                 $delete = $zdb->delete(self::TABLE);
                 $zdb->execute($delete);
 
+                $zdb->handleSequence(
+                    self::TABLE,
+                    count($this->defaults)
+                );
+
                 $this->insert($zdb, $this->defaults);
 
                 Analog::log(
index e48045971e9e61ad7d36136d69265fddcfa2add9..36d647c444531d8175e9389f571873f8063c4c74 100644 (file)
@@ -110,21 +110,22 @@ class Install extends atoum
         );
 
         $knowns = array(
-            '0.60' => 'upgrade-to-0.60-pgsql.sql',
-            '0.61' => 'upgrade-to-0.61-pgsql.sql',
-            '0.62' => 'upgrade-to-0.62-pgsql.sql',
-            '0.63' => 'upgrade-to-0.63-pgsql.sql',
-            '0.70' => 'upgrade-to-0.70.php',
-            '0.71' => 'upgrade-to-0.71-pgsql.sql',
-            '0.74' => 'upgrade-to-0.74-pgsql.sql',
-            '0.75' => 'upgrade-to-0.75-pgsql.sql',
-            '0.76' => 'upgrade-to-0.76-pgsql.sql',
-            '0.8'  => 'upgrade-to-0.8.php',
-            '0.81' => 'upgrade-to-0.81-pgsql.sql',
-            '0.82' => 'upgrade-to-0.82-pgsql.sql',
-            '0.91' => 'upgrade-to-0.91-pgsql.sql',
-            '0.92' => 'upgrade-to-0.92-pgsql.sql',
-            '0.93' => 'upgrade-to-0.93-pgsql.sql'
+            '0.60'  => 'upgrade-to-0.60-pgsql.sql',
+            '0.61'  => 'upgrade-to-0.61-pgsql.sql',
+            '0.62'  => 'upgrade-to-0.62-pgsql.sql',
+            '0.63'  => 'upgrade-to-0.63-pgsql.sql',
+            '0.70'  => 'upgrade-to-0.70.php',
+            '0.71'  => 'upgrade-to-0.71-pgsql.sql',
+            '0.74'  => 'upgrade-to-0.74-pgsql.sql',
+            '0.75'  => 'upgrade-to-0.75-pgsql.sql',
+            '0.76'  => 'upgrade-to-0.76-pgsql.sql',
+            '0.8'   => 'upgrade-to-0.8.php',
+            '0.81'  => 'upgrade-to-0.81-pgsql.sql',
+            '0.82'  => 'upgrade-to-0.82-pgsql.sql',
+            '0.91'  => 'upgrade-to-0.91-pgsql.sql',
+            '0.92'  => 'upgrade-to-0.92-pgsql.sql',
+            '0.93'  => 'upgrade-to-0.93-pgsql.sql',
+            '0.931' => 'upgrade-to-0.931-pgsql.sql'
         );
 
         $this->array($update_scripts)
diff --git a/tests/Galette/Entity/tests/units/Texts.php b/tests/Galette/Entity/tests/units/Texts.php
new file mode 100644 (file)
index 0000000..5f03cdc
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Text tests
+ *
+ * PHP version 5
+ *
+ * Copyright © 2019 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Repository
+ * @package   GaletteTests
+ *
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2019 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version   SVN: $Id$
+ * @link      http://galette.tuxfamily.org
+ * @since     2019-12-20
+ */
+
+namespace Galette\Entity\test\units;
+
+use \atoum;
+use Zend\Db\Adapter\Adapter;
+
+/**
+ * Text tests
+ *
+ * @category  Entity
+ * @name      Texts
+ * @package   GaletteTests
+ * @author    Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2020 The Galette Team
+ * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link      http://galette.tuxfamily.org
+ * @since     2020-01-18
+ */
+class Texts extends atoum
+{
+    private $zdb;
+    private $remove = [];
+    private $i18n;
+    private $texts_fields;
+    private $preferences;
+
+    /**
+     * Set up tests
+     *
+     * @param string $testMethod Calling method
+     *
+     * @return void
+     */
+    public function beforeTestMethod($testMethod)
+    {
+        $this->zdb = new \Galette\Core\Db();
+        $this->i18n = new \Galette\Core\I18n(
+            \Galette\Core\I18n::DEFAULT_LANG
+        );
+        $this->preferences = new \Galette\Core\Preferences(
+            $this->zdb
+        );
+        include_once GALETTE_ROOT . 'includes/fields_defs/texts_fields.php';
+        $this->texts_fields = $texts_fields;
+    }
+
+    /**
+     * Test getList
+     *
+     * @return void
+     */
+    public function testGetList()
+    {
+        global $zdb;
+        $zdb = $this->zdb;
+
+        $texts = new \Galette\Entity\Texts(
+            $this->texts_fields,
+            $this->preferences
+        );
+        $texts->installInit();
+
+        $list = $texts->getRefs(\Galette\Core\I18n::DEFAULT_LANG);
+        $this->array($list)->hasSize(12);
+
+        if ($this->zdb->isPostgres()) {
+            $select = $this->zdb->select($texts::TABLE . '_id_seq');
+            $select->columns(['last_value']);
+            $results = $this->zdb->execute($select);
+            $result = $results->current();
+            $this->integer($result->last_value)
+                 ->isGreaterThanOrEqualTo(12, 'Incorrect texts sequence ' . $result->last_value);
+
+            $this->zdb->db->query(
+                'SELECT setval(\'' . PREFIX_DB . $texts::TABLE . '_id_seq\', 1)',
+                Adapter::QUERY_MODE_EXECUTE
+            );
+        }
+
+        //reinstall texts
+        $texts->installInit(false);
+
+        $list = $texts->getRefs('en_US');
+        $this->array($list)->hasSize(12);
+
+        if ($this->zdb->isPostgres()) {
+            $select = $this->zdb->select($texts::TABLE . '_id_seq');
+            $select->columns(['last_value']);
+            $results = $this->zdb->execute($select);
+            $result = $results->current();
+            $this->integer($result->last_value)
+                 ->isGreaterThanOrEqualTo(12, 'Incorrect texts sequence ' . $result->last_value);
+        }
+    }
+}