diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 0c8dce4..ead4c43 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -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 }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e39d0a3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,61 +0,0 @@ -language: php - -sudo: false - -servics: - - mysql - -addons: - firefox: "47.0.1" - apt: - packages: - - openjdk-8-jre-headless - -cache: - directories: - - $HOME/.composer/cache - - $HOME/.npm - -php: - - 7.2 - - 7.3 - - 7.4 - -env: - global: - - IGNORE_PATHS=db/upgrade.php,classes/form/duration.php,classes/form/itemspertime.php - matrix: - - MOODLE_BRANCH=MOODLE_36_STABLE DB=mysqli - - MOODLE_BRANCH=MOODLE_37_STABLE DB=mysqli - - MOODLE_BRANCH=MOODLE_38_STABLE DB=mysqli - - MOODLE_BRANCH=MOODLE_39_STABLE DB=mysqli - - MOODLE_BRANCH=master DB=mysqli -# Ignore PHP 7.4 with MOODLE_36_STABLE & MOODLE_37_STABLE since they contain deprecated code when using PHP 7.4 or higher -matrix: - exclude: - - php: 7.4 - env: MOODLE_BRANCH=MOODLE_36_STABLE DB=mysqli - - php: 7.4 - env: MOODLE_BRANCH=MOODLE_37_STABLE DB=mysqli - allow_failures: - - env: MOODLE_BRANCH=master DB=mysqli - -before_install: - - phpenv config-rm xdebug.ini - - | - if [ "${MOODLE_BRANCH}" = "MOODLE_36_STABLE" ]; then - nvm install 8.9 - nvm use 8.9 - else - nvm install 14.6.0 - nvm use 14.6.0 - fi - - cd ../.. - - composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 - - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" - -install: - - moodle-plugin-ci install - -script: - - moodle-plugin-ci phpunit \ No newline at end of file diff --git a/README.md b/README.md index c16ba05..402a7f6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/classes/controller.php b/classes/controller.php index ac877cf..d40e4af 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -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(); } /** diff --git a/classes/event/backup_activity_created.php b/classes/event/backup_activity_created.php new file mode 100644 index 0000000..2a0c21f --- /dev/null +++ b/classes/event/backup_activity_created.php @@ -0,0 +1,39 @@ +. + +/** + * 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()}"; + } +} diff --git a/classes/event/backup_activity_started.php b/classes/event/backup_activity_started.php new file mode 100644 index 0000000..2be0acf --- /dev/null +++ b/classes/event/backup_activity_started.php @@ -0,0 +1,44 @@ +. + +/** + * 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()}"; + } +} diff --git a/classes/event/base.php b/classes/event/base.php new file mode 100644 index 0000000..b44a9dd --- /dev/null +++ b/classes/event/base.php @@ -0,0 +1,104 @@ +. + +/** + * 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); + } +} diff --git a/classes/event/restore_activity_created.php b/classes/event/restore_activity_created.php new file mode 100644 index 0000000..a944f4a --- /dev/null +++ b/classes/event/restore_activity_created.php @@ -0,0 +1,33 @@ +. + +/** + * 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()}"; + } +} diff --git a/classes/event/restore_activity_started.php b/classes/event/restore_activity_started.php new file mode 100644 index 0000000..ef2cbf1 --- /dev/null +++ b/classes/event/restore_activity_started.php @@ -0,0 +1,52 @@ +. + +/** + * 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(), + ]); + } +} diff --git a/classes/event/sharing_cart_item_deleted.php b/classes/event/sharing_cart_item_deleted.php new file mode 100644 index 0000000..81396b1 --- /dev/null +++ b/classes/event/sharing_cart_item_deleted.php @@ -0,0 +1,54 @@ +. + +/** + * 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, + ]); + } +} diff --git a/version.php b/version.php index a898abe..71749bc 100644 --- a/version.php +++ b/version.php @@ -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;