diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index cf10edef..d47c9472 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -55,7 +55,7 @@ public function execute() { $certificateexecutionperiod = (int)get_config('customcert', 'certificateexecutionperiod'); // Get the last processed batch and total certificates to process. - $taskprogress = $DB->get_record('customcert_task_progress', ['taskname' => 'email_certificate_task']); + $taskprogress = $DB->get_record('customcert_email_task_prgrs', ['taskname' => 'email_certificate_task']); $lastprocessed = $taskprogress->last_processed; // Get all the certificates that have requested someone get emailed. @@ -101,7 +101,7 @@ public function execute() { // Store the total count of certificates in the database. $totalcertificatestoprocess = count($customcerts); - $DB->set_field('customcert_task_progress', 'total_certificate_to_process', $totalcertificatestoprocess, [ + $DB->set_field('customcert_email_task_prgrs', 'total_certificate_to_process', $totalcertificatestoprocess, [ 'taskname' => 'email_certificate_task', ]); @@ -174,11 +174,9 @@ public function execute() { // Now, get a list of users who can view and issue the certificate but have not yet. // Get users with the mod/customcert:receiveissue capability in the Custom Certificate module context. - $userswithissue = get_users_by_capability($context, 'mod/customcert:receiveissue', - 'u.id, username, firstname, lastname, email, firstnamephonetic, lastnamephonetic, middlename, alternatename'); + $userswithissue = get_users_by_capability($context, 'mod/customcert:receiveissue'); // Get users with mod/customcert:view capability. - $userswithview = get_users_by_capability($context, 'mod/customcert:view', - 'u.id, username, firstname, lastname, email, firstnamephonetic, lastnamephonetic, middlename, alternatename'); + $userswithview = get_users_by_capability($context, 'mod/customcert:view'); // Users with both mod/customcert:view and mod/customcert:receiveissue cabapilities. $userswithissueview = array_intersect_key($userswithissue, $userswithview); @@ -313,14 +311,17 @@ public function execute() { // Set the field so that it is emailed. $issueids[] = $user->issueid; } + if (!empty($issueids)) { - $DB->set_field_select('customcert_issues', 'emailed', 1, 'id IN (' . implode(',', $issueids) . ')'); + list($sql, $params) = $DB->get_in_or_equal($issueids, SQL_PARAMS_NAMED, 'id'); + $DB->set_field_select('customcert_issues', 'emailed', 1, 'id ' . $sql, $params); } } + // Update the last processed position, if run in batches. if ($certificatesperrun > 0) { $newlastprocessed = $lastprocessed + count($certificates); - $DB->set_field('customcert_task_progress', 'last_processed', $newlastprocessed, [ + $DB->set_field('customcert_email_task_prgrs', 'last_processed', $newlastprocessed, [ 'taskname' => 'email_certificate_task', ]); } diff --git a/db/install.php b/db/install.php index c0dfdf9c..c78723fc 100644 --- a/db/install.php +++ b/db/install.php @@ -18,7 +18,7 @@ * Customcert module upgrade code. * * @package mod_customcert - * @copyright 2016 Mark Nelson + * @copyright 2024 Mohamed Atia * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -35,18 +35,13 @@ function xmldb_customcert_install() { global $DB; - $dbman = $DB->get_manager(); - - // Add a default row to the customcert_task_progress table. + // Add a default row to the customcert_email_task_prgrs table. $defaultdata = new stdClass(); $defaultdata->taskname = 'email_certificate_task'; $defaultdata->last_processed = 0; $defaultdata->total_certificate_to_process = 0; - // Write close to ensure the transaction is committed. - \core\session\manager::write_close(); - // Insert the default data into the table. - $DB->insert_record('customcert_task_progress', $defaultdata); + $DB->insert_record('customcert_email_task_prgrs', $defaultdata); return true; } diff --git a/db/install.xml b/db/install.xml index ad4a3279..19d4439b 100644 --- a/db/install.xml +++ b/db/install.xml @@ -100,7 +100,7 @@ - +
diff --git a/db/upgrade.php b/db/upgrade.php index 945f6b68..4440093d 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -235,38 +235,36 @@ function xmldb_customcert_upgrade($oldversion) { upgrade_mod_savepoint(true, 2023042405, 'customcert'); } - if ($oldversion < 2023042408) { + if ($oldversion < 2023042409) { - // Define table customcert_task_progress to be created. - $table = new xmldb_table('customcert_task_progress'); + // Define table customcert_email_task_prgrs to be created. + $table = new xmldb_table('customcert_email_task_prgrs'); - // Adding fields to table customcert_task_progress. + // Adding fields to table customcert_email_task_prgrs. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('taskname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'email_certificate_task'); $table->add_field('last_processed', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); $table->add_field('total_certificate_to_process', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, '0'); - // Adding keys to table customcert_task_progress. + // Adding keys to table customcert_email_task_prgrs. $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); - $table->add_key('usermodified', XMLDB_KEY_FOREIGN, ['usermodified'], 'user', ['id']); - // Conditionally launch create table for customcert_task_progress. + // Conditionally launch create table for customcert_email_task_prgrs. if (!$dbman->table_exists($table)) { $dbman->create_table($table); - // Add a default row to the customcert_task_progress table. + + // Add a default row to the customcert_email_task_prgrs table. $defaultdata = new stdClass(); $defaultdata->taskname = 'email_certificate_task'; $defaultdata->last_processed = 0; $defaultdata->total_certificate_to_process = 0; - // Write close to ensure the transaction is committed. - \core\session\manager::write_close(); - // Insert the default data into the table. - $DB->insert_record('customcert_task_progress', $defaultdata); + $DB->insert_record('customcert_email_task_prgrs', $defaultdata); } + // Customcert savepoint reached. - upgrade_mod_savepoint(true, 2023042408, 'customcert'); + upgrade_mod_savepoint(true, 2023042409, 'customcert'); } return true; } diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 56dd707d..9cd1686a 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -33,6 +33,10 @@ $string['awardedto'] = 'Awarded to'; $string['cannotverifyallcertificates'] = 'You do not have the permission to verify all certificates on the site.'; $string['certificate'] = 'Certificate'; +$string['certificateexecutionperiod'] = 'Certificate execution period'; +$string['certificateexecutionperiod_desc'] = 'Specify the period for which certificates should be executed based on their end date. Set to 0 to execute all certificates, regardless of their age.'; +$string['certificatesperrun'] = 'Certificates per run'; +$string['certificatesperrun_desc'] = 'Enter the number of certificates to process per scheduled task run where 0 means it will process all certificates.'; $string['code'] = 'Code'; $string['copy'] = 'Copy'; $string['coursetimereq'] = 'Required minutes in course'; @@ -122,6 +126,8 @@ $string['gradeoutcome'] = 'Outcome'; $string['height'] = 'Height'; $string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.'; +$string['includeinnotvisiblecourses'] = 'Include certificates in hidden courses'; +$string['includeinnotvisiblecourses_desc'] = 'Check this box to include certificates in courses that are not visible to the user.'; $string['invalidcode'] = 'Invalid code supplied.'; $string['invalidcolour'] = 'Invalid colour chosen, please enter a valid HTML colour name, or a six-digit, or three-digit hexadecimal colour.'; $string['invalidelementwidthorheightnotnumber'] = 'Please enter a valid number.'; @@ -192,6 +198,8 @@ $string['saveandcontinue'] = 'Save and continue'; $string['savechangespreview'] = 'Save changes and preview'; $string['savetemplate'] = 'Save template'; +$string['scheduledtaskconfigdesc'] = 'Configure the settings for the scheduled task that processes certificates.'; +$string['scheduledtaskconfigheading'] = 'Scheduled task configuration'; $string['search:activity'] = 'Custom certificate - activity information'; $string['setprotection'] = 'Set protection'; $string['setprotection_help'] = 'Choose the actions you wish to prevent users from performing on this certificate.'; @@ -230,12 +238,3 @@ // Acess API. $string['customcert:managelanguages'] = 'Manage language on edit form'; - -$string['certificatesperrun'] = 'Certificates per run'; -$string['certificatesperrun_desc'] = 'Enter the number of certificates to process per scheduled task run where 0 means it will process all certificates.'; -$string['includeinnotvisiblecourses'] = 'Include certificates in hidden courses'; -$string['includeinnotvisiblecourses_desc'] = 'Check this box to include certificates in courses that are not visible to the user.'; -$string['certificateexecutionperiod'] = 'Certificate execution period'; -$string['certificateexecutionperiod_desc'] = 'Specify the period for which certificates should be executed based on their end date. Set to 0 to execute all certificates, regardless of their age.'; -$string['scheduledtaskconfigheading'] = 'Scheduled task configuration'; -$string['scheduledtaskconfigdesc'] = 'Configure the settings for the scheduled task that processes certificates.'; diff --git a/settings.php b/settings.php index 1e9a2708..a7fd5266 100644 --- a/settings.php +++ b/settings.php @@ -58,7 +58,6 @@ new moodle_url('/mod/customcert/download_all_certificates.php'), '')); } - $settings->add(new admin_setting_heading('scheduledtaskconfig', get_string('scheduledtaskconfigheading', 'customcert'), get_string('scheduledtaskconfigdesc', 'customcert')));