1 diff --git a/src/Admin/Migrations/Backup.php b/src/Admin/Migrations/Backup.php
5 +++ b/src/Admin/Migrations/Backup.php
8 +/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
10 +# ***** BEGIN LICENSE BLOCK *****
11 +# This file is part of Plume Framework, a simple PHP Application Framework.
12 +# Copyright (C) 2001-2009 Loic d'Anterroches and contributors.
14 +# Plume Framework is free software; you can redistribute it and/or modify
15 +# it under the terms of the GNU Lesser General Public License as published by
16 +# the Free Software Foundation; either version 2.1 of the License, or
17 +# (at your option) any later version.
19 +# Plume Framework is distributed in the hope that it will be useful,
20 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
21 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 +# GNU Lesser General Public License for more details.
24 +# You should have received a copy of the GNU Lesser General Public License
25 +# along with this program; if not, write to the Free Software
26 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 +# ***** END LICENSE BLOCK ***** */
31 + * Backup of the Plume Framework.
33 + * Backup all the data of the framework models. By default the backup
34 + * name will be the date YYYY-MM-DD.
36 + * @param string Path to the folder where to store the backup
37 + * @param string Name of the backup (null)
38 + * @return int The backup was correctly written
40 +function Admin_Migrations_Backup_run($folder, $name=null)
47 + // Now, for each table, we dump the content in json, this is a
48 + // memory intensive operation
50 + foreach ($models as $model) {
51 + $to_json[$model] = Pluf_Test_Fixture::dump($model, false);
53 + if (null == $name) {
54 + $name = date('Y-m-d');
56 + return file_put_contents(sprintf('%s/%s-Admin.json', $folder, $name),
57 + json_encode($to_json), LOCK_EX);
61 + * Restore Pluf from a backup.
63 + * @param string Path to the backup folder
64 + * @param string Backup name
65 + * @return bool Success
67 +function Admin_Migrations_Backup_restore($folder, $name)
74 + $schema = new Admin_DB_Schema($db);
75 + foreach ($models as $model) {
76 + $schema->model = new $model();
77 + $schema->createTables();
80 + $full_data = json_decode(file_get_contents(sprintf('%s/%s-Admin.json', $folder, $name)), true);
81 + foreach ($full_data as $model => $data) {
82 + Pluf_Test_Fixture::load($data, false);