first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<?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/>.
/**
* Provides support for the conversion of moodle1 backup to the moodle2 format
*
* @package block_rss_client
* @copyright 2012 Paul Nicholls
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Block conversion handler for rss_client
*/
class moodle1_block_rss_client_handler extends moodle1_block_handler {
public function process_block(array $data) {
parent::process_block($data);
$instanceid = $data['id'];
$contextid = $this->converter->get_contextid(CONTEXT_BLOCK, $data['id']);
// Moodle 1.9 backups do not include sufficient data to restore feeds, so we need an empty shell rss_client.xml
// for the restore process to find
$this->open_xml_writer("course/blocks/{$data['name']}_{$instanceid}/rss_client.xml");
$this->xmlwriter->begin_tag('block', array('id' => $instanceid, 'contextid' => $contextid, 'blockname' => 'rss_client'));
$this->xmlwriter->begin_tag('rss_client', array('id' => $instanceid));
$this->xmlwriter->full_tag('feeds', '');
$this->xmlwriter->end_tag('rss_client');
$this->xmlwriter->end_tag('block');
$this->close_xml_writer();
return $data;
}
}
@@ -0,0 +1,54 @@
<?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_rss_client
* @subpackage backup-moodle2
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/blocks/rss_client/backup/moodle2/backup_rss_client_stepslib.php'); // We have structure steps
/**
* Specialised backup task for the rss_client block
* (has own DB structures to backup)
*
* TODO: Finish phpdocs
*/
class backup_rss_client_block_task extends backup_block_task {
protected function define_my_settings() {
}
protected function define_my_steps() {
// rss_client has one structure step
$this->add_step(new backup_rss_client_block_structure_step('rss_client_structure', 'rss_client.xml'));
}
public function get_fileareas() {
return array(); // No associated fileareas
}
public function get_configdata_encoded_attributes() {
return array(); // No special handling of configdata
}
public static function encode_content_links($content) {
return $content; // No special encoding of links
}
}
@@ -0,0 +1,83 @@
<?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_rss_client
* @subpackage backup-moodle2
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the backup steps that wll be used by the backup_rss_client_block_task
*/
/**
* Define the complete forum structure for backup, with file and id annotations
*/
class backup_rss_client_block_structure_step extends backup_block_structure_step {
protected function define_structure() {
global $DB;
// Get the block
$block = $DB->get_record('block_instances', array('id' => $this->task->get_blockid()));
// Extract configdata
$config = unserialize_object(base64_decode($block->configdata));
// Get array of used rss feeds
if (!empty($config->rssid)) {
$feedids = $config->rssid;
// Get the IN corresponding query
list($in_sql, $in_params) = $DB->get_in_or_equal($feedids);
// Define all the in_params as sqlparams
foreach ($in_params as $key => $value) {
$in_params[$key] = backup_helper::is_sqlparam($value);
}
}
// Define each element separated
$rss_client = new backup_nested_element('rss_client', array('id'), null);
$feeds = new backup_nested_element('feeds');
$feed = new backup_nested_element('feed', array('id'), array(
'title', 'preferredtitle', 'description', 'shared',
'url'));
// Build the tree
$rss_client->add_child($feeds);
$feeds->add_child($feed);
// Define sources
$rss_client->set_source_array(array((object)array('id' => $this->task->get_blockid())));
// Only if there are feeds
if (!empty($config->rssid)) {
$feed->set_source_sql("
SELECT *
FROM {block_rss_client}
WHERE id $in_sql", $in_params);
}
// Annotations (none)
// Return the root element (rss_client), wrapped into standard block structure
return $this->prepare_block_structure($rss_client);
}
}
@@ -0,0 +1,58 @@
<?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_rss_client
* @subpackage backup-moodle2
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/blocks/rss_client/backup/moodle2/restore_rss_client_stepslib.php'); // We have structure steps
/**
* Specialised restore task for the rss_client block
* (has own DB structures to backup)
*
* TODO: Finish phpdocs
*/
class restore_rss_client_block_task extends restore_block_task {
protected function define_my_settings() {
}
protected function define_my_steps() {
// rss_client has one structure step
$this->add_step(new restore_rss_client_block_structure_step('rss_client_structure', 'rss_client.xml'));
}
public function get_fileareas() {
return array(); // No associated fileareas
}
public function get_configdata_encoded_attributes() {
return array(); // No special handling of configdata
}
public static function define_decode_contents() {
return array();
}
public static function define_decode_rules() {
return array();
}
}
@@ -0,0 +1,87 @@
<?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_rss_client
* @subpackage backup-moodle2
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that wll be used by the restore_rss_client_block_task
*/
/**
* Define the complete rss_client structure for restore
*/
class restore_rss_client_block_structure_step extends restore_structure_step {
protected function define_structure() {
$paths = array();
$paths[] = new restore_path_element('block', '/block', true);
$paths[] = new restore_path_element('rss_client', '/block/rss_client');
$paths[] = new restore_path_element('feed', '/block/rss_client/feeds/feed');
return $paths;
}
public function process_block($data) {
global $DB;
$data = (object)$data;
$feedsarr = array(); // To accumulate feeds
// For any reason (non multiple, dupe detected...) block not restored, return
if (!$this->task->get_blockid()) {
return;
}
// Iterate over all the feed elements, creating them if needed
if (isset($data->rss_client['feeds']['feed'])) {
foreach ($data->rss_client['feeds']['feed'] as $feed) {
$feed = (object)$feed;
// Look if the same feed is available by url and (shared or userid)
$select = 'url = :url AND (shared = 1 OR userid = :userid)';
$params = array('url' => $feed->url, 'userid' => $this->task->get_userid());
// The feed already exists, use it
if ($feedid = $DB->get_field_select('block_rss_client', 'id', $select, $params, IGNORE_MULTIPLE)) {
$feedsarr[] = $feedid;
// The feed doesn't exist, create it
} else {
$feed->userid = $this->task->get_userid();
$feedid = $DB->insert_record('block_rss_client', $feed);
$feedsarr[] = $feedid;
}
}
}
// Adjust the serialized configdata->rssid to the created/mapped feeds
// Get the configdata
$configdata = $DB->get_field('block_instances', 'configdata', array('id' => $this->task->get_blockid()));
// Extract configdata
$config = unserialize_object(base64_decode($configdata));
// Set array of used rss feeds
$config->rssid = $feedsarr;
// Serialize back the configdata
$configdata = base64_encode(serialize($config));
// Set the configdata back
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $this->task->get_blockid()));
}
}