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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

        $sql = preg_replace_callback('/^\.read (.+\.sql)$/m', function ($match) use ($dir) {
            return file_get_contents($dir . DIRECTORY_SEPARATOR . $match[1]) . "\n";
        }, $sql);

        return $this->exec($sql);
    }

    public function deleteUndoTriggers()
    {
        $triggers = $this->getAssoc('SELECT name, name FROM sqlite_master
            WHERE type = \'trigger\' AND name LIKE \'!_%!_log!__t\' ESCAPE \'!\';');

        foreach ($triggers as $trigger)
        {
            $this->exec(sprintf('DROP TRIGGER %s;', $this->quoteIdentifier($trigger)));
        }
    }

    public function createUndoTriggers()
    {
        $this->exec('CREATE TABLE undolog (
            seq INTEGER PRIMARY KEY,
            sql TEXT NOT NULL,
            date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
            type TEXT NOT NULL,
            action TEXT NOT NULL
        );');

        // List all tables except SQLite tables
        $tables = $this->getAssoc('SELECT name, name FROM sqlite_master
            WHERE type = \'table\'
            AND name NOT LIKE \'sqlite!_%\' ESCAPE \'!\' AND name NOT LIKE \'wiki!_recherche%\' ESCAPE \'!\'
            AND name != \'undolog\';');


        $query = 'CREATE TRIGGER _%table_log_it AFTER INSERT ON %table BEGIN
                DELETE FROM undolog WHERE rowid IN (SELECT rowid FROM undolog LIMIT 500,1000);
                INSERT INTO undolog (type, action, sql) VALUES (\'%table\', \'I\', \'DELETE FROM %table WHERE rowid=\'||new.rowid);
            END;
            CREATE TRIGGER _%table_log_ut AFTER UPDATE ON %table BEGIN
                DELETE FROM undolog WHERE rowid IN (SELECT rowid FROM undolog LIMIT 500,1000);
                INSERT INTO undolog (type, action, sql) VALUES (\'%table\', \'U\',  \'UPDATE %table SET %columns_update WHERE rowid = \'||old.rowid);
            END;
            CREATE TRIGGER _%table_log_dt BEFORE DELETE ON %table BEGIN
                DELETE FROM undolog WHERE rowid IN (SELECT rowid FROM undolog LIMIT 500,1000);
                INSERT INTO undolog (type, action, sql) VALUES (\'%table\', \'D\', \'INSERT INTO %table (rowid, %columns_list) VALUES(\'||old.rowid||\', %columns_insert)\');
            END;';

        foreach ($tables as $table)
        {
            $columns = $this->getAssoc(sprintf('PRAGMA table_info(%s);', $this->quoteIdentifier($table)));
            $columns_insert = [];
            $columns_update = [];

            foreach ($columns as &$name)
            {
                $columns_update[] = sprintf('%s = \'||quote(old.%1$s)||\'', $name);
                $columns_insert[] = sprintf('\'||quote(old.%s)||\'', $name);
            }

            $sql = strtr($query, [
                '%table' => $table,
                '%columns_list' => implode(', ', $columns),
                '%columns_update' => implode(', ', $columns_update),
                '%columns_insert' => implode(', ', $columns_insert),
            ]);

            $this->exec($sql);
        }
    }
}







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
78
79
80
81
82
83
84
85

































































        $sql = preg_replace_callback('/^\.read (.+\.sql)$/m', function ($match) use ($dir) {
            return file_get_contents($dir . DIRECTORY_SEPARATOR . $match[1]) . "\n";
        }, $sql);

        return $this->exec($sql);
    }
}
































































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

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
        $db->begin();

        $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\');');

        $db->import(ROOT . '/include/data/0.9.1.sql');

        $db->commit();

        $db->createUndoTriggers();
    }

    Utils::clearCaches();

    $config->setVersion(garradin_version());

    Static_Cache::remove('upgrade');







<
<







256
257
258
259
260
261
262


263
264
265
266
267
268
269
        $db->begin();

        $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\');');

        $db->import(ROOT . '/include/data/0.9.1.sql');

        $db->commit();


    }

    Utils::clearCaches();

    $config->setVersion(garradin_version());

    Static_Cache::remove('upgrade');