Overview
Comment:Suppression des undo triggers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: c0b5eec9e9c66ccc36c26420a34dad5bf43ad289
User & Date: bohwaz on 2019-01-22 10:51:08
Other Links: branch diff | manifest | tags
Context
2019-01-22
11:37
Merge trunk avec dev check-in: 344c04b375 user: bohwaz tags: dev
10:51
Suppression des undo triggers check-in: c0b5eec9e9 user: bohwaz tags: dev
2019-01-17
10:01
Merge avec branche trunk check-in: 511aee5412 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/DB.php from [dadf975219] to [5b61f7e017].

    78     78   
    79     79           $sql = preg_replace_callback('/^\.read (.+\.sql)$/m', function ($match) use ($dir) {
    80     80               return file_get_contents($dir . DIRECTORY_SEPARATOR . $match[1]) . "\n";
    81     81           }, $sql);
    82     82   
    83     83           return $this->exec($sql);
    84     84       }
    85         -
    86         -    public function deleteUndoTriggers()
    87         -    {
    88         -        $triggers = $this->getAssoc('SELECT name, name FROM sqlite_master
    89         -            WHERE type = \'trigger\' AND name LIKE \'!_%!_log!__t\' ESCAPE \'!\';');
    90         -
    91         -        foreach ($triggers as $trigger)
    92         -        {
    93         -            $this->exec(sprintf('DROP TRIGGER %s;', $this->quoteIdentifier($trigger)));
    94         -        }
    95         -    }
    96         -
    97         -    public function createUndoTriggers()
    98         -    {
    99         -        $this->exec('CREATE TABLE undolog (
   100         -            seq INTEGER PRIMARY KEY,
   101         -            sql TEXT NOT NULL,
   102         -            date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
   103         -            type TEXT NOT NULL,
   104         -            action TEXT NOT NULL
   105         -        );');
   106         -
   107         -        // List all tables except SQLite tables
   108         -        $tables = $this->getAssoc('SELECT name, name FROM sqlite_master
   109         -            WHERE type = \'table\'
   110         -            AND name NOT LIKE \'sqlite!_%\' ESCAPE \'!\' AND name NOT LIKE \'wiki!_recherche%\' ESCAPE \'!\'
   111         -            AND name != \'undolog\';');
   112         -
   113         -
   114         -        $query = 'CREATE TRIGGER _%table_log_it AFTER INSERT ON %table BEGIN
   115         -                DELETE FROM undolog WHERE rowid IN (SELECT rowid FROM undolog LIMIT 500,1000);
   116         -                INSERT INTO undolog (type, action, sql) VALUES (\'%table\', \'I\', \'DELETE FROM %table WHERE rowid=\'||new.rowid);
   117         -            END;
   118         -            CREATE TRIGGER _%table_log_ut AFTER UPDATE ON %table BEGIN
   119         -                DELETE FROM undolog WHERE rowid IN (SELECT rowid FROM undolog LIMIT 500,1000);
   120         -                INSERT INTO undolog (type, action, sql) VALUES (\'%table\', \'U\',  \'UPDATE %table SET %columns_update WHERE rowid = \'||old.rowid);
   121         -            END;
   122         -            CREATE TRIGGER _%table_log_dt BEFORE DELETE ON %table BEGIN
   123         -                DELETE FROM undolog WHERE rowid IN (SELECT rowid FROM undolog LIMIT 500,1000);
   124         -                INSERT INTO undolog (type, action, sql) VALUES (\'%table\', \'D\', \'INSERT INTO %table (rowid, %columns_list) VALUES(\'||old.rowid||\', %columns_insert)\');
   125         -            END;';
   126         -
   127         -        foreach ($tables as $table)
   128         -        {
   129         -            $columns = $this->getAssoc(sprintf('PRAGMA table_info(%s);', $this->quoteIdentifier($table)));
   130         -            $columns_insert = [];
   131         -            $columns_update = [];
   132         -
   133         -            foreach ($columns as &$name)
   134         -            {
   135         -                $columns_update[] = sprintf('%s = \'||quote(old.%1$s)||\'', $name);
   136         -                $columns_insert[] = sprintf('\'||quote(old.%s)||\'', $name);
   137         -            }
   138         -
   139         -            $sql = strtr($query, [
   140         -                '%table' => $table,
   141         -                '%columns_list' => implode(', ', $columns),
   142         -                '%columns_update' => implode(', ', $columns_update),
   143         -                '%columns_insert' => implode(', ', $columns_insert),
   144         -            ]);
   145         -
   146         -            $this->exec($sql);
   147         -        }
   148         -    }
   149     85   }

Modified src/www/admin/upgrade.php from [8ddde4bfb3] to [92ea3090d6].

   256    256           $db->begin();
   257    257   
   258    258           $db->exec('INSERT INTO "compta_categories" VALUES(NULL,-1,\'Licences fédérales\',\'Licences payées pour les adhérents (par exemple fédération sportive etc.)\',\'652\');');
   259    259   
   260    260           $db->import(ROOT . '/include/data/0.9.1.sql');
   261    261   
   262    262           $db->commit();
   263         -
   264         -        $db->createUndoTriggers();
   265    263       }
   266    264   
   267    265       Utils::clearCaches();
   268    266   
   269    267       $config->setVersion(garradin_version());
   270    268   
   271    269       Static_Cache::remove('upgrade');