This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
migrate.php
204 lines (177 loc) · 9.23 KB
/
migrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package block_quickmail
* @copyright 2008 onwards Louisiana State University
* @copyright 2008 onwards Chad Mazilly, Robert Russo, Jason Peak, Dave Elliott, Adam Zapletal, Philip Cali
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true);
require_once('../../config.php');
require_once($CFG->dirroot . '/blocks/quickmail/lib.php';
// Authentication.
require_login();
// Must be a site admin to do this!!
if (!is_siteadmin()) {
throw new moodle_exception('cannotuseadmin', 'error');
}
$systemcontext = context_system::instance();
$PAGE->set_context($systemcontext);
$PAGE->set_url(new moodle_url('/blocks/quickmail/migrate.php'));
// Construct the page.
$PAGE->set_pagetype('block-quickmail');
$PAGE->set_pagelayout('standard');
$PAGE->set_title(block_quickmail_string::get('pluginname') . ': ' . block_quickmail_string::get('migrate'));
$PAGE->navbar->add(block_quickmail_string::get('pluginname'));
$PAGE->navbar->add(block_quickmail_string::get('migrate'));
$PAGE->set_heading(block_quickmail_string::get('pluginname') . ': ' . block_quickmail_string::get('migrate'));
echo $OUTPUT->header();
$taskurl = new moodle_url('/admin/tool/task/scheduledtasks.php', [
'action' => 'edit',
'task' => 'block_quickmail\\tasks\\migrate_legacy_data_task'
]);
$settingsurl = new moodle_url('/admin/settings.php', [
'section' => 'blocksettingquickmail',
]);
// If old tables do not exist, either the process has completed -OR- the user has dropped the old tables.
if (!block_quickmail\migrator\migrator::old_tables_exist()) {
echo '<h4>Migration Progress: Complete</h4>
<p>It looks like the migration process is complete,
or Quickmail\'s old tables no longer exist, so nothing else needs to be done.</p>';
// Otherwise, there may still work to be done.
} else {
// Pull the current numbers.
$totaldraftcount = block_quickmail\migrator\migrator::total_count('drafts');
$migrateddraftcount = block_quickmail\migrator\migrator::migrated_count('drafts');
$totallogcount = block_quickmail\migrator\migrator::total_count('log');
$migratedlogcount = block_quickmail\migrator\migrator::migrated_count('log');
$taskenabled = block_quickmail\migrator\migrator::is_enabled();
$status = 'not-begun';
if ($totaldraftcount + $totallogcount == 0) {
$status = 'nothing-to-migrate';
} else if (($totaldraftcount + $totallogcount - $migrateddraftcount - $migratedlogcount) == 0) {
$status = 'process-complete';
} else if ($migrateddraftcount || $migratedlogcount) {
$status = 'needs-more-work';
}
if ($status == 'nothing-to-migrate') {
if ($taskenabled) {
echo '<h4>Migration Progress: No Data To Migrate</h4>
<p>This tool allows you to <strong>migrate historical data
from Quickmail v1 to v2</strong>, but it looks like you have no
historical data to migrate. However, please note that <strong>
the scheduled migration task is still running</strong>.
This will not harm anything, but you can safely disable it
forever by going to
<a href="' . $taskurl . '">block_quickmail\tasks\migrate_legacy_data_task</a>
in the admin panel and marking it as disabled.</p> ';
} else {
echo '<h4>Migration Progress: No Data To Migrate</h4>
<p>This tool allows you to <strong>migrate historical data
from Quickmail v1 to v2</strong>, but it looks like
you have no historical data to migrate.</p>';
}
} else if ($status == 'process-complete') {
if ($taskenabled) {
echo '<h4>Migration Progress: Complete</h4>
<p>It looks like all of your old Quickmail data has been migrated
over to the new version, congratulations! However, please note that
<strong> the scheduled migration task is still running</strong>.
This will not harm anything, but you can safely disable it forever.
If you want to disable the task, you can go to
<a href="' . $taskurl . '">block_quickmail\tasks\migrate_legacy_data_task</a>
in the admin panel and mark it as disabled.</p>';
} else {
echo '<h4>Migration Progress: Complete</h4>
<p>It looks like all of your old Quickmail data has been migrated over
to the new version and there is nothing left to do, congratulations!</p>';
}
} else if ($status == 'needs-more-work' && ! $taskenabled) {
echo '<h4>Migration Progress: Disabled But Incomplete</h4>
<p>This tool allows you to <strong>migrate historical data from
Quickmail v1 to v2</strong>. It looks like the process was started,
but <strong>is now currently disabled</strong>. If you want
to continue the migration process, please enable the
<a href="' . $taskurl . '">block_quickmail\tasks\migrate_legacy_data_task</a>
in the admin panel, then come back to this page to see the progress.</p>';
} else if (!$taskenabled) {
echo '<h4>Migration Progress: Not Enabled</h4>
<p>Things have changed in Quickmail. This tool allows you to
<strong>migrate historical data from Quickmail v1 to v2</strong>.
If you want to do this, please enable the
<a href="' . $taskurl . '">block_quickmail\tasks\migrate_legacy_data_task</a>
in the admin panel, then come back to this page to see the progress.</p>';
} else {
echo '<h4>Migration Progress: Working</h4>
<p>This process is currently running. If you want to stop
this process, please disable the
<a href="' . $taskurl . '">block_quickmail\tasks\migrate_legacy_data_task</a>
in the admin panel. If you want to speed things up, you
can try to increase the "Migration Chunk Size" in the
<a href="' . $settingsurl . '">Quickmail settings</a>.
<i>Note: If you disable the task right now, any data that has been
migrated up to this point will be retained.</i></p>';
// Draft migration status.
$bar = new progress_bar('drafts_bar', 500, true);
$bar->update($migrateddraftcount,
$totaldraftcount,
'Drafts (' . number_format($migrateddraftcount) . ' / ' . number_format($totaldraftcount) . ')');
// Log migration status.
$bar = new progress_bar('log_bar', 500, true);
$bar->update($migratedlogcount,
$totallogcount,
'Logs (' . number_format($migratedlogcount) . ' / ' . number_format($totallogcount) . ')');
}
if (in_array($status, ['process-complete', 'nothing-to-migrate'])) {
echo '<br><br><h4>Delete Old Tables?</h4>';
if ($status == 'process-complete') {
echo '<p>Since this process is complete, you can now safely drop the old tables:</p>';
} else {
echo '<p>Since there is nothing to migrate, you can now safely drop the old tables:</p>';
}
echo '
<pre>block_quickmail_log</pre>
<pre>block_quickmail_drafts</pre>
';
if ($taskenabled) {
echo '<p>If you do wish to drop these tables,
please disable this migration task first by going to
<a href="' . $taskurl . '">block_quickmail\tasks\migrate_legacy_data_task</a>
in the admin panel and marking it as disabled.';
} else {
echo '<p>Click the button below to automatically remove them now,
or come back to this page at any time to do so.</p>';
// Display a form to allow for deletion of old tables.
$mform = new block_quickmail\forms\migration_post_actions_form();
if ($mform->is_cancelled()) {
// Should not happen, but don't do anything just in case.
redirect($PAGE->url);
} else if ($submission = $mform->get_data()) {
if (property_exists($submission, 'submitbutton')) {
try {
block_quickmail\migrator\migrator::drop_old_tables();
redirect($PAGE->url, 'Old tables have been successfully removed!', 'success');
} catch (\Exception $e) {
redirect($PAGE->url, $e->getMessage(), 'error');
}
}
} else {
$mform->display();
}
}
}
}
echo $OUTPUT->footer();