-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from ArloSoftware/ARLO-60
ARLO-60: Adding buttong to resync old registrations with an adhoc task
- Loading branch information
Showing
12 changed files
with
246 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ModalForm from 'core_form/modalform'; | ||
import Config from 'core/config'; | ||
import {get_string as getString} from 'core/str'; | ||
|
||
export const init = (linkSelector, formClass) => { | ||
let syncbutton = document.querySelector(linkSelector); | ||
|
||
syncbutton.addEventListener('click', async(e) => { | ||
e.preventDefault(); | ||
|
||
const form = new ModalForm(({ | ||
formClass, | ||
args: {}, | ||
modalConfig: { | ||
title: await getString('dateselector', 'enrol_arlo'), | ||
}, | ||
saveButtonText: await getString('synchronize', 'enrol_arlo'), | ||
returnFocus: e.currentTarget | ||
})); | ||
|
||
form.addEventListener(form.events.FORM_SUBMITTED, (e) => { | ||
const response = e.detail; | ||
let redirect = `${Config.wwwroot}/enrol/arlo/admin/apiretries.php?`; | ||
let first = false; | ||
for (let key in response) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
redirect = redirect + '&'; | ||
} | ||
redirect = redirect + `${key}=${response[key]}`; | ||
} | ||
window.location.assign(redirect); | ||
}); | ||
|
||
form.show(); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?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/>. | ||
|
||
namespace enrol_arlo\form; | ||
|
||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir . '/formslib.php'); | ||
use core_form\dynamic_form; | ||
use enrol_arlo\task\enrolments_adhoc; | ||
use moodle_url; | ||
use stdClass; | ||
|
||
class syncold extends dynamic_form { | ||
|
||
/** | ||
* Get context. | ||
* | ||
* @return \context | ||
* @throws \dml_exception | ||
*/ | ||
protected function get_context_for_dynamic_submission(): \context { | ||
return \context_system::instance(); | ||
} | ||
|
||
/** | ||
* Check access. | ||
* | ||
* @return void | ||
* @throws \dml_exception | ||
* @throws \required_capability_exception | ||
*/ | ||
protected function check_access_for_dynamic_submission(): void { | ||
require_capability('moodle/course:create', \context_system::instance()); | ||
} | ||
|
||
/** | ||
* Process submission. | ||
* | ||
* @return array | ||
*/ | ||
public function process_dynamic_submission() { | ||
$data = $this->get_data(); | ||
$task = new enrolments_adhoc(); | ||
$task->set_custom_data($data->startdate); | ||
\core\task\manager::queue_adhoc_task($task); | ||
return ['message' => 'taskqueued']; | ||
} | ||
|
||
/** | ||
* Set form data. | ||
* | ||
* @return void | ||
* @throws Exception No record in persistent table | ||
*/ | ||
public function set_data_for_dynamic_submission(): void { | ||
$this->set_data(new stdClass()); | ||
} | ||
|
||
/** | ||
* Get page url. | ||
* | ||
* @return moodle_url | ||
*/ | ||
protected function get_page_url_for_dynamic_submission(): moodle_url { | ||
return new moodle_url('/enrol/arlo/admin/apiretries.php'); | ||
} | ||
|
||
public function definition() { | ||
global $DB, $COURSE; | ||
$form = $this->_form; | ||
$form->addElement('date_selector', 'startdate', get_string('syncsince', 'enrol_arlo')); | ||
$form->addHelpButton('startdate', 'syncsince', 'enrol_arlo'); | ||
} | ||
|
||
public function validation($data, $files) { | ||
$errors = parent::validation($data, $files); | ||
$time = time(); | ||
if ($data['startdate'] > $time) { | ||
$errors['startdate'] = get_string('invalidstartdate', 'enrol_arlo'); | ||
} | ||
return $errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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/>. | ||
|
||
namespace enrol_arlo\task; | ||
|
||
use core\task\adhoc_task; | ||
use core\task\scheduled_task; | ||
use enrol_arlo\api; | ||
use enrol_arlo\local\job\memberships_job; | ||
use enrol_arlo\manager; | ||
use null_progress_trace; | ||
use text_progress_trace; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Create Moodle enrolments based off Arlo registrations adhoc. | ||
* | ||
* @package enrol_arlo | ||
* @copyright 2020 LearningWorks Ltd {@link http://www.learningworks.co.nz} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class enrolments_adhoc extends adhoc_task { | ||
|
||
/** | ||
* Get schedule task human readable name. | ||
* | ||
* @return string | ||
* @throws \coding_exception | ||
*/ | ||
public function get_name() { | ||
return get_string('enrolmentstaskadhoc', 'enrol_arlo'); | ||
} | ||
|
||
/** | ||
* Execute the task. | ||
* | ||
* @throws \coding_exception | ||
* @throws \dml_exception | ||
* @throws \moodle_exception | ||
*/ | ||
public function execute() { | ||
global $CFG; | ||
require_once($CFG->dirroot . '/enrol/arlo/lib.php'); | ||
if (!enrol_is_enabled('arlo')) { | ||
return; | ||
} | ||
$trace = new null_progress_trace(); | ||
if ($CFG->debug == DEBUG_DEVELOPER) { | ||
$trace = new text_progress_trace(); | ||
} | ||
$timetosync = $this->get_custom_data(); | ||
memberships_job::sync_memberships($trace, $timetosync); | ||
|
||
$manager = new manager(); | ||
$manager->process_email_queue(); | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters