Skip to content

Commit

Permalink
#118: Add feature: async backup/restore
Browse files Browse the repository at this point in the history
Improve backup/restore process by using adhoc task

Fix session lock error
  • Loading branch information
sampraxis committed Jan 5, 2024
1 parent e5da825 commit 749fb96
Show file tree
Hide file tree
Showing 22 changed files with 1,586 additions and 178 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Warning: PHP versions 7.2 and older are deprecated, and will cause problems, unr

Change Log
----------
* 4.4, release 1 2024.01.03
* New feature - Added the ability to copy & restore asynchronously.
* Improved backup & restore process.
* New upgrade will remove sharing cart items that doesn't have the backup files.
* 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.
Expand Down
3 changes: 3 additions & 0 deletions amd/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

define(['jquery', 'core/modal_factory', 'core/modal_events'], function($, ModalFactory, ModalEvents) {
return {
/**
* @param {string} addMethod
*/
init: function(addMethod) {

$(document).ready(function() {
Expand Down
14 changes: 12 additions & 2 deletions block_sharing_cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ public function get_content() {
/* Place the <noscript> tag to give out an error message if JavaScript is not enabled in the browser.
* Adding bootstrap classes to show colored info in bootstrap based themes. */
$noscript = html_writer::tag('noscript',
html_writer::tag('div', get_string('requirejs', __CLASS__), array('class' => 'error alert alert-danger'))
html_writer::tag(
'div',
get_string('requirejs', __CLASS__),
['class' => 'error alert alert-danger']
)
);
$html = $noscript . $html;

Expand All @@ -105,7 +109,13 @@ public function get_content() {
$this->page->requires->css('/blocks/sharing_cart/custom.css');
}
$this->page->requires->jquery();
$this->page->requires->js_call_amd('block_sharing_cart/script', 'init', ['add_method' => get_config('block_sharing_cart', 'add_to_sharing_cart')]);
$this->page->requires->js_call_amd(
'block_sharing_cart/script',
'init',
[
'add_method' => get_config('block_sharing_cart', 'add_to_sharing_cart')
]
);
$this->page->requires->strings_for_js(
['yes', 'no', 'ok', 'cancel', 'error', 'edit', 'move', 'delete', 'movehere'],
'moodle'
Expand Down
85 changes: 85 additions & 0 deletions classes/backup_task_options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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;


use block_sharing_cart\repositories\backup_options;

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

class backup_task_options
{
private array $data;

public function __construct(array $data = [])
{
$this->data = $data;
}

public function get_cm_id(): int
{
return $this->data['cm_id'] ?? 0;
}

public function get_course_id(): int
{
return $this->data['course_id'] ?? 0;
}

public function get_section_id(): int
{
return $this->data['section_id'] ?? 0;
}

public function get_user_id(): int
{
return $this->data['user_id'] ?? 0;
}

public function get_settings(): array
{
return $this->data['settings'] ?? [];
}

public function get_sharing_cart_record(): ?object
{
if (isset($this->data['sharing_cart_record'])) {
return (object)$this->data['sharing_cart_record'];
}
return null;
}

public function get_backup_options(): backup_options
{
return new backup_options($this->get_settings());
}

public static function create_by_json(string $json): self
{
return new self(json_decode($json, true));
}
}
Loading

0 comments on commit 749fb96

Please sign in to comment.