From bf2986c2e308483a7842e493e54c928bedbfb069 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 27 Jul 2015 09:25:28 +0800 Subject: [PATCH] MDL-50572 youtube: Disable Youtube Disabled Youtube repository and Youtube Tag Block on new Moodle installations. --- blocks/tag_youtube/db/install.php | 36 +++++++++++++ .../tests/block_tag_youtube_test.php | 51 +++++++++++++++++++ repository/tests/generator_test.php | 2 +- repository/youtube/db/install.php | 17 +++---- 4 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 blocks/tag_youtube/db/install.php create mode 100644 blocks/tag_youtube/tests/block_tag_youtube_test.php diff --git a/blocks/tag_youtube/db/install.php b/blocks/tag_youtube/db/install.php new file mode 100644 index 00000000000..0572762fa96 --- /dev/null +++ b/blocks/tag_youtube/db/install.php @@ -0,0 +1,36 @@ +. + +/** + * Tag Youtube block installation. + * + * @package block_tag_youtube + * @copyright 2015 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Sets the install values for the tag_youtube entry in the block table. + * + * @return void + */ +function xmldb_block_tag_youtube_install() { + global $DB; + + // Disable this block by default. + $DB->set_field('block', 'visible', 0, array('name' => 'tag_youtube')); +} + diff --git a/blocks/tag_youtube/tests/block_tag_youtube_test.php b/blocks/tag_youtube/tests/block_tag_youtube_test.php new file mode 100644 index 00000000000..6434c445e4a --- /dev/null +++ b/blocks/tag_youtube/tests/block_tag_youtube_test.php @@ -0,0 +1,51 @@ +. + +/** + * Block Tag Youtube tests + * + * @package block_tag_youtube + * @category test + * @copyright 2015 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Block Tag Youtube test class. + * + * @package block_tag_youtube + * @category test + * @copyright 2015 Jun Pataleta + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class core_block_tag_youtube_testcase extends advanced_testcase { + + /** + * Testing the tag youtube block's initial state after a new installation. + * + * @return void + */ + public function test_after_install() { + global $DB; + + $this->resetAfterTest(true); + + // Assert that tag_youtube entry exists and that its visible attribute is set to 0 (disabled). + $this->assertTrue($DB->record_exists('block', array('name' => 'tag_youtube', 'visible' => 0))); + } +} diff --git a/repository/tests/generator_test.php b/repository/tests/generator_test.php index d21fc355dde..9f24d63f1dc 100644 --- a/repository/tests/generator_test.php +++ b/repository/tests/generator_test.php @@ -50,7 +50,7 @@ class core_repository_generator_testcase extends advanced_testcase { 'user', 'webdav', 'wikimedia', 'youtube'); // The ones enabled during installation. - $alreadyenabled = array('local', 'recent', 'upload', 'url', 'user', 'wikimedia', 'youtube'); + $alreadyenabled = array('local', 'recent', 'upload', 'url', 'user', 'wikimedia'); // Enable all the repositories which are not enabled yet. foreach ($all as $type) { diff --git a/repository/youtube/db/install.php b/repository/youtube/db/install.php index 654f9e98eb8..28a4f0beb28 100644 --- a/repository/youtube/db/install.php +++ b/repository/youtube/db/install.php @@ -23,17 +23,14 @@ */ /** - * Create a default instance of the youtube repository + * This was supposed to be the installer script for the Youtube repository. * - * @return bool A status indicating success or failure + * However, since the Youtube repository is disabled in new Moodle installations from 3.0, and since we cannot + * just delete this file, the function's contents has been replaced to just return true. + * See https://tracker.moodle.org/browse/MDL-50572 for more details. + * + * @return bool Return true. */ function xmldb_repository_youtube_install() { - global $CFG; - $result = true; - require_once($CFG->dirroot.'/repository/lib.php'); - $youtubeplugin = new repository_type('youtube', array(), true); - if(!$id = $youtubeplugin->create(true)) { - $result = false; - } - return $result; + return true; }