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 * @package block_rss_client 19 * @subpackage backup-moodle2 20 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 /** 25 * Define all the restore steps that wll be used by the restore_rss_client_block_task 26 */ 27 28 /** 29 * Define the complete rss_client structure for restore 30 */ 31 class restore_rss_client_block_structure_step extends restore_structure_step { 32 33 protected function define_structure() { 34 35 $paths = array(); 36 37 $paths[] = new restore_path_element('block', '/block', true); 38 $paths[] = new restore_path_element('rss_client', '/block/rss_client'); 39 $paths[] = new restore_path_element('feed', '/block/rss_client/feeds/feed'); 40 41 return $paths; 42 } 43 44 public function process_block($data) { 45 global $DB; 46 47 $data = (object)$data; 48 $feedsarr = array(); // To accumulate feeds 49 50 // For any reason (non multiple, dupe detected...) block not restored, return 51 if (!$this->task->get_blockid()) { 52 return; 53 } 54 55 // Iterate over all the feed elements, creating them if needed 56 if (isset($data->rss_client['feeds']['feed'])) { 57 foreach ($data->rss_client['feeds']['feed'] as $feed) { 58 $feed = (object)$feed; 59 // Look if the same feed is available by url and (shared or userid) 60 $select = 'url = :url AND (shared = 1 OR userid = :userid)'; 61 $params = array('url' => $feed->url, 'userid' => $this->task->get_userid()); 62 // The feed already exists, use it 63 if ($feedid = $DB->get_field_select('block_rss_client', 'id', $select, $params, IGNORE_MULTIPLE)) { 64 $feedsarr[] = $feedid; 65 66 // The feed doesn't exist, create it 67 } else { 68 $feed->userid = $this->task->get_userid(); 69 $feedid = $DB->insert_record('block_rss_client', $feed); 70 $feedsarr[] = $feedid; 71 } 72 } 73 } 74 75 // Adjust the serialized configdata->rssid to the created/mapped feeds 76 // Get the configdata 77 $configdata = $DB->get_field('block_instances', 'configdata', array('id' => $this->task->get_blockid())); 78 // Extract configdata 79 $config = unserialize_object(base64_decode($configdata)); 80 // Set array of used rss feeds 81 $config->rssid = $feedsarr; 82 // Serialize back the configdata 83 $configdata = base64_encode(serialize($config)); 84 // Set the configdata back 85 $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $this->task->get_blockid())); 86 } 87 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body