Skip to content

Commit

Permalink
added missing UpdateService
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Sep 21, 2022
1 parent 51925c9 commit e47b3f2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
79 changes: 79 additions & 0 deletions classes/UpdateService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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/>.

/**
* Class for the Report Service
*
* @package mod_ivs
* @author Ghostthinker GmbH <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2017 onwards Ghostthinker GmbH (https://ghostthinker.de/)
*/

namespace mod_ivs;

use Exception;

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

/**
* Class ReportService
*/
class UpdateService {

private \moodle_database $database;
private \moodle_transaction $transaction;

/**
* UpdateService constructor.
*/
public function __construct() {
global $DB;
$this->database = $DB;
$this->transaction = $this->database->start_delegated_transaction();
}

public function settingInvertUpdate() {

$ivssettings =
$this->database->get_records_sql("SELECT * FROM {ivs_settings} WHERE name = 'default_random_question' OR name = 'list_item_buttons_hover_enabled' OR name = 'hide_when_inactive' OR name = 'annotation_realm_default_enabled'");

$configplugins =
$this->database->get_records_sql("SELECT * FROM {config_plugins} WHERE (name = 'default_random_question' OR name = 'list_item_buttons_hover_enabled' OR name = 'hide_when_inactive' OR name = 'annotation_realm_default_enabled') AND plugin = 'mod_ivs'");
try {
if (!empty($ivssettings)) {
foreach ($ivssettings as $ivssetting) {
$invertedvalue = (integer) !$ivssetting->value;
$this->database->execute("UPDATE {ivs_settings} SET value = :value WHERE target_id = :target_id",
['value' => $invertedvalue, 'target_id' => $ivssetting->target_id]);
}
}
if (!empty($configplugins)) {
foreach ($configplugins as $configplugin) {
$invertedvalue = (integer) !$configplugin->value;
$this->database->execute("UPDATE {config_plugins} SET value = :value WHERE id = :id AND plugin = 'mod_ivs'",
['value' => $invertedvalue, 'id' => $configplugin->id]);
}
}
} catch (\dml_exception $e) {
$this->transaction->rollback($e);
}

$this->transaction->allow_commit();

}

}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'mod_ivs';
$plugin->release = 'v1.13.809';
$plugin->version = 2022092000;
$plugin->release = 'v1.13.810';
$plugin->version = 2022092100;
$plugin->requires = 2014051200;
$plugin->maturity = MATURITY_BETA;
$plugin->cron = 0;
Expand Down

0 comments on commit e47b3f2

Please sign in to comment.