Merge branch 'MDL-33294' of git://github.com/danpoltawski/moodle
[moodle.git] / portfolio / picasa / db / upgrade.php
CommitLineData
b7acfd64
DP
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 * @param int $oldversion the version we are upgrading from
19 * @return bool result
20 */
21function xmldb_portfolio_picasa_upgrade($oldversion) {
22 global $CFG, $DB;
23
24 $dbman = $DB->get_manager();
25
26 if ($oldversion < 2012053000) {
27 // Delete old user preferences containing authsub tokens.
28 $DB->delete_records('user_preferences', array('name' => 'google_authsub_sesskey_picasa'));
29 upgrade_plugin_savepoint(true, 2012053000, 'portfolio', 'picasa');
30 }
31
32 if ($oldversion < 2012053001) {
33 $existing = $DB->get_record('portfolio_instance', array('plugin' => 'picasa'), '*', IGNORE_MISSING);
34
35 if ($existing) {
36 portfolio_picasa_admin_upgrade_notification();
37 }
38
39 upgrade_plugin_savepoint(true, 2012053001, 'portfolio', 'picasa');
40 }
41
42 return true;
43}
44
45function portfolio_picasa_admin_upgrade_notification() {
46 $admins = get_admins();
47
48 if (empty($admins)) {
49 return;
50 }
51 $mainadmin = reset($admins);
52
53 foreach ($admins as $admin) {
54 $message = new stdClass();
55 $message->component = 'moodle';
56 $message->name = 'notices';
57 $message->userfrom = $mainadmin;
58 $message->userto = $admin;
59 $message->smallmessage = get_string('oauth2upgrade_message_small', 'portfolio_picasa');
60 $message->subject = get_string('oauth2upgrade_message_subject', 'portfolio_picasa');
61 $message->fullmessage = get_string('oauth2upgrade_message_content', 'portfolio_picasa');
62 $message->fullmessagehtml = get_string('oauth2upgrade_message_content', 'portfolio_picasa');
63 $message->fullmessageformat = FORMAT_PLAIN;
64 $message->notification = 1;
65 message_send($message);
66 }
67}