Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

praxisdigital/moodle-block_sharing_cart#118 #187

Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#111: Fix restore issue
Fix restore settings that cause restore issue

Added moodle log when a sharing cart item got backup, restored or deleted
sampraxis committed Dec 19, 2023

Verified

This commit was signed with the committer’s verified signature.
sampraxis Sam Møller
commit 6dbd6fd04ad069ac2972bd4e0045de24790dfd36
22 changes: 8 additions & 14 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -16,31 +16,25 @@ jobs:
strategy:
matrix:
include:
## Moodle 4.1+ with PHP 8.0
- os: ubuntu-22.04
php: 8.0
db: mysqli
moodle: MOODLE_401_STABLE
experimental: false
# Future supported versions
## Moodle 4.1+ with PHP 8.1
- os: ubuntu-22.04
php: 8.1
db: mysqli
moodle: MOODLE_401_STABLE
experimental: true
## Moodle development version with PHP 8.1
## Moodle 4.2+ with PHP 8.2
- os: ubuntu-22.04
php: 8.1
php: 8.2
db: mysqli
moodle: master
moodle: MOODLE_402_STABLE
experimental: true
## Moodle 4.1+ with PHP 8.2
## Moodle 4.3+ with PHP 8.2
- os: ubuntu-22.04
php: 8.2
db: mysqli
moodle: MOODLE_401_STABLE
moodle: MOODLE_403_STABLE
experimental: true
# Future supported versions
## Moodle development version with PHP 8.2
- os: ubuntu-22.04
php: 8.2
@@ -68,13 +62,13 @@ jobs:
ini-values: 'max_input_vars=5000'

- name: Checking out code from moodle/moodle
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: moodle/moodle
ref: ${{ matrix.moodle }}

- name: Check out code from ${{ github.repository }}
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/blocks/sharing_cart
ref: ${{ github.ref }}
61 changes: 0 additions & 61 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,11 @@ Warning: PHP versions 7.2 and older are deprecated, and will cause problems, unr

Change Log
----------
* 4.3, release 2 2023.12.15
* Fixed sharing cart restore process.
* Added moodle log when a sharing cart item got backup, restored or deleted.
When the backup file has user completion data but the backup file has no user data.
It causes Moodle try to restore something that does not exist.
* 4.3, release 1 2023.11.01
* Adapted Sharing Cart to new core Moodle 4.3 Backup feature which allows backup without editing the backup.
* 4.2, release skipped.
40 changes: 38 additions & 2 deletions classes/controller.php
Original file line number Diff line number Diff line change
@@ -25,9 +25,14 @@
namespace block_sharing_cart;

use backup_controller;
use block_sharing_cart\event\backup_activity_created;
use block_sharing_cart\event\backup_activity_started;
use block_sharing_cart\event\restore_activity_created;
use block_sharing_cart\event\restore_activity_started;
use block_sharing_cart\event\section_backedup;
use block_sharing_cart\event\section_deleted;
use block_sharing_cart\event\section_restored;
use block_sharing_cart\event\sharing_cart_item_deleted;
use block_sharing_cart\exceptions\no_backup_support_exception;
use block_sharing_cart\repositories\course_repository;
use cache_helper;
@@ -215,6 +220,11 @@ public function backup(
// THIS FILE REQUIRES $CFG, DO NOT REMOVE IT
require_once __DIR__ . '/../../../backup/util/includes/backup_includes.php';

backup_activity_started::create_by_course_module_id(
$course,
$cmid
)->trigger();

// validate parameters and capabilities
$cm = \get_coursemodule_from_id(null, $cmid, 0, false, MUST_EXIST);
$context = \context_module::instance($cm->id);
@@ -295,7 +305,15 @@ public function backup(
'course' => $course,
'section' => $section
));
return $record->insert();
$id = $record->insert();

backup_activity_created::create_by_course_module_id(
$course,
$cmid,
$id
)->trigger();

return $id;
}

/**
@@ -507,6 +525,8 @@ public function restore($id, $courseid, $sectionnumber): void {
require_once __DIR__ . '/../../../backup/util/includes/restore_includes.php';
require_once __DIR__ . '/../backup/util/helper/restore_fix_missings_helper.php';

restore_activity_started::create_by_sharing_cart_backup_id($id)->trigger();

// cleanup temporary files when we exit this scope
$tempfiles = array();
$scope = new scoped(function() use (&$tempfiles) {
@@ -551,6 +571,15 @@ public function restore($id, $courseid, $sectionnumber): void {
if ($task->setting_exists('overwrite_conf')) {
$task->get_setting('overwrite_conf')->set_value(false);
}
if ($task->setting_exists('userscompletion')) {
$has_user_data = false;
if ($task->setting_exists('user')) {
$has_user_data = (bool)$task->get_setting('userscompletion')->get_value();
}
if (!$has_user_data) {
$task->get_setting('userscompletion')->set_value(false);
}
}
}
if (\get_config('block_sharing_cart', 'workaround_qtypes')) {
\restore_fix_missings_helper::fix_plan($controller->get_plan());
@@ -567,6 +596,12 @@ public function restore($id, $courseid, $sectionnumber): void {
// Fire event.
$event = \core\event\course_module_created::create_from_cm($cm);
$event->trigger();

restore_activity_created::create_by_course_module_id(
$course->id,
$cmid,
$id
)->trigger();
}
}
\rebuild_course_cache($course->id);
@@ -726,8 +761,9 @@ public function delete($id): void {

$storage = new storage();
$storage->delete($record->filename);

$record->delete();

sharing_cart_item_deleted::create_by_sharing_cart_item_id($id, $record->course)->trigger();
}

/**
39 changes: 39 additions & 0 deletions classes/event/backup_activity_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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/>.

/**
* Sharing Cart
*
* @package block_sharing_cart
* @copyright 2017 (C) VERSION2, INC.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_sharing_cart\event;


// @codeCoverageIgnoreStart
defined('MOODLE_INTERNAL') || die();
// @codeCoverageIgnoreEnd


class backup_activity_created extends base
{
public function get_description(): string
{
return "User with id {$this->userid} created a backup of the activity with course module id {$this->get_course_module_id()}";
}
}
44 changes: 44 additions & 0 deletions classes/event/backup_activity_started.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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/>.

/**
* Sharing Cart
*
* @package block_sharing_cart
* @copyright 2017 (C) VERSION2, INC.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_sharing_cart\event;


// @codeCoverageIgnoreStart
defined('MOODLE_INTERNAL') || die();
// @codeCoverageIgnoreEnd


class backup_activity_started extends base
{
protected function get_crud(): string
{
return static::CRUD_READ;
}

public function get_description(): string
{
return "User with id {$this->userid} started a backup of the activity with course module id {$this->get_course_module_id()}";
}
}
104 changes: 104 additions & 0 deletions classes/event/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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/>.

/**
* Sharing Cart
*
* @package block_sharing_cart
* @copyright 2017 (C) VERSION2, INC.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_sharing_cart\event;


use cm_info;

// @codeCoverageIgnoreStart
defined('MOODLE_INTERNAL') || die();
// @codeCoverageIgnoreEnd


/**
* @method static self create(array $data)
*/
abstract class base extends \core\event\base
{
private static array $course_modules = [];

public const CRUD_CREATED = 'c';
public const CRUD_READ = 'r';
public const CRUD_UPDATE = 'u';
public const CRUD_DELETE = 'd';

protected function get_edu_level(): int
{
return static::LEVEL_OTHER;
}

protected function get_crud(): string
{
return static::CRUD_CREATED;
}

protected function init(): void
{
$this->data['crud'] = $this->get_crud();
$this->data['edulevel'] = $this->get_edu_level();
$this->data['objecttable'] = 'block_sharing_cart';
}

protected function get_course_module_id(): int
{
return $this->other['cmid'] ?? 0;
}

public static function create_by_course_module_id(
int $course_id,
int $course_module_id,
int $sharing_cart_backup_id = 0
): self
{
return static::create_by_course_module(
self::get_course_module_by_id($course_id, $course_module_id),
$sharing_cart_backup_id
);
}

public static function create_by_course_module(
cm_info $cm,
int $sharing_cart_backup_id = 0
): self
{
return static::create([
'objectid' => $sharing_cart_backup_id,
'courseid' => $cm->course,
'context' => $cm->context,
'other' => [
'courseid' => $cm->course,
'sectionid' => $cm->section,
'sectionnum' => $cm->sectionnum,
'cmid' => $cm->id,
],
]);
}

private static function get_course_module_by_id(int $course_id, int $course_module_id): cm_info
{
return self::$course_modules[$course_id][$course_module_id] ??=
get_fast_modinfo($course_id)->get_cm($course_module_id);
}
}
33 changes: 33 additions & 0 deletions classes/event/restore_activity_created.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Sharing Cart
*
* @package block_sharing_cart
* @copyright 2017 (C) VERSION2, INC.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_sharing_cart\event;

class restore_activity_created extends base
{
public function get_description(): string
{
return "User with id {$this->userid} restored a backup of the activity with course module id {$this->get_course_module_id()}";
}
}
52 changes: 52 additions & 0 deletions classes/event/restore_activity_started.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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/>.

/**
* Sharing Cart
*
* @package block_sharing_cart
* @copyright 2017 (C) VERSION2, INC.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_sharing_cart\event;


/**
* @method static self create(array $data)
*/
class restore_activity_started extends base
{
protected function get_crud(): string
{
return static::CRUD_READ;
}

public function get_description(): string
{
return "User with id {$this->userid} started a restore of the activity with sharing cart item id {$this->objectid}";
}

public static function create_by_sharing_cart_backup_id(
int $sharing_cart_backup_id
): self
{
return static::create([
'objectid' => $sharing_cart_backup_id,
'context' => \context_system::instance(),
]);
}
}
54 changes: 54 additions & 0 deletions classes/event/sharing_cart_item_deleted.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Sharing Cart
*
* @package block_sharing_cart
* @copyright 2017 (C) VERSION2, INC.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_sharing_cart\event;

/**
* @method static self create(array $data)
*/
class sharing_cart_item_deleted extends base
{
protected function get_crud(): string
{
return static::CRUD_DELETE;
}

public function get_description(): string
{
return "User with id {$this->userid} deleted a sharing cart item with id {$this->objectid}";
}

public static function create_by_sharing_cart_item_id(
int $sharing_cart_item_id,
int $course_id = 0
): self
{
$context = $course_id > 0 ? \context_course::instance($course_id) : \context_system::instance();
return static::create([
'objectid' => $sharing_cart_item_id,
'context' => $context,
'courseid' => $course_id,
]);
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@

/** @var object $plugin */
$plugin->component = 'block_sharing_cart';
$plugin->version = 2023110100;
$plugin->version = 2023121500;
$plugin->requires = 2021051704; // Moodle 3.11.4
$plugin->release = '4.3, release 1';
$plugin->release = '4.3, release 2';
$plugin->maturity = MATURITY_STABLE;