Skip to content

Commit

Permalink
MDL-73342 course_summary: Disable the block by default
Browse files Browse the repository at this point in the history
Co-authored by: Amaia Anabitarte <amaia@moodle.com>
  • Loading branch information
sarjona committed Jan 11, 2022
1 parent 8044279 commit b1a772d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
33 changes: 33 additions & 0 deletions blocks/course_summary/db/install.php
@@ -0,0 +1,33 @@
<?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/>.

/**
* Course summary block installation.
*
* @package block_course_summary
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Perform the post-install procedures.
*/
function xmldb_block_course_summary_install() {
global $DB;

// Disable course_summary on new installs by default.
$DB->set_field('block', 'visible', 0, ['name' => 'course_summary']);
}
13 changes: 12 additions & 1 deletion blocks/course_summary/db/upgrade.php
Expand Up @@ -46,7 +46,7 @@
* @param object $block
*/
function xmldb_block_course_summary_upgrade($oldversion, $block) {
global $CFG;
global $CFG, $DB;

// Automatically generated Moodle v3.6.0 release upgrade line.
// Put any upgrade step following this.
Expand All @@ -60,5 +60,16 @@ function xmldb_block_course_summary_upgrade($oldversion, $block) {
// Automatically generated Moodle v3.9.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2021121600) {
// From Moodle 4.0, this block has been disabled by default in new installations.
// If the site has no instances of this block, it will disabled during the upgrading process too.
$totalcount = $DB->count_records('block_instances', ['blockname' => 'course_summary']);
if ($totalcount == 0) {
$DB->set_field('block', 'visible', 0, ['name' => 'course_summary']);
}

upgrade_block_savepoint(true, 2021121600, 'course_summary', false);
}

return true;
}
Expand Up @@ -16,6 +16,7 @@ Feature: Course summary block used in a course
| user | course | role |
| student1 | C101 | student |
| teacher1 | C101 | editingteacher |
And I enable "course_summary" "block" plugin
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Course/site summary" block
Expand Down
Expand Up @@ -6,6 +6,7 @@ Feature: Course summary block used on the frontpage

Background:
Given I log in as "admin"
And I enable "course_summary" "block" plugin
And I am on site homepage
And I turn editing mode on
And I add the "Course/site summary" block
Expand Down
2 changes: 1 addition & 1 deletion blocks/course_summary/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021052500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2021121600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'block_course_summary'; // Full name of the plugin (used for diagnostics)

0 comments on commit b1a772d

Please sign in to comment.