1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Customcert background image element upgrade code.
|
|
|
19 |
*
|
|
|
20 |
* @package customcertelement_bgimage
|
|
|
21 |
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Customcert background image element upgrade code.
|
|
|
27 |
*
|
|
|
28 |
* @param int $oldversion the version we are upgrading from
|
|
|
29 |
* @return bool always true
|
|
|
30 |
*/
|
|
|
31 |
function xmldb_customcertelement_bgimage_upgrade($oldversion) {
|
|
|
32 |
global $DB;
|
|
|
33 |
|
|
|
34 |
if ($oldversion < 2016120501) {
|
|
|
35 |
// Go through each 'image' element and update the file stored information.
|
|
|
36 |
if ($images = $DB->get_records_select('customcert_elements', $DB->sql_compare_text('element') . ' = \'bgimage\'')) {
|
|
|
37 |
// Create a file storage instance we are going to use to create pathname hashes.
|
|
|
38 |
$fs = get_file_storage();
|
|
|
39 |
// Go through and update the details.
|
|
|
40 |
foreach ($images as $image) {
|
|
|
41 |
// Get the current data we have stored for this element.
|
|
|
42 |
$elementinfo = json_decode($image->data);
|
|
|
43 |
if ($file = $fs->get_file_by_hash($elementinfo->pathnamehash)) {
|
|
|
44 |
$arrtostore = [
|
|
|
45 |
'contextid' => $file->get_contextid(),
|
|
|
46 |
'filearea' => $file->get_filearea(),
|
|
|
47 |
'itemid' => $file->get_itemid(),
|
|
|
48 |
'filepath' => $file->get_filepath(),
|
|
|
49 |
'filename' => $file->get_filename(),
|
|
|
50 |
'width' => (int) $elementinfo->width,
|
|
|
51 |
'height' => (int) $elementinfo->height,
|
|
|
52 |
];
|
|
|
53 |
$arrtostore = json_encode($arrtostore);
|
|
|
54 |
$DB->set_field('customcert_elements', 'data', $arrtostore, ['id' => $image->id]);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// Savepoint reached.
|
|
|
60 |
upgrade_plugin_savepoint(true, 2016120501, 'customcertelement', 'bgimage');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
return true;
|
|
|
64 |
}
|