Skip to content

Commit

Permalink
Ignore the invalid module occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
aydevworks committed Feb 9, 2024
1 parent 51489f9 commit 725a701
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
66 changes: 31 additions & 35 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,35 @@ public static function get_manager(): ?manager {
* Fetch component grades data (MAB) from SITS.
*
* @param array $modocc module occurrences of the current course.
* @return bool
* @return void
*/
public function fetch_component_grades_from_sits(array $modocc): bool {
try {
if (!empty($modocc)) {
foreach ($modocc as $occ) {
// Get the cache.
$key = implode('_',
[
cachemanager::CACHE_AREA_COMPONENTGRADES,
$occ->mod_code,
$occ->mod_occ_mav,
$occ->mod_occ_psl_code,
$occ->mod_occ_year_code,
]
);

// Replace '/' with '_' for simple key.
$key = str_replace('/', '_', $key);

// This cache is not really used.
// It is only used to check if the component grades have been fetched for this module occurrence.
$cache = cachemanager::get_cache(cachemanager::CACHE_AREA_COMPONENTGRADES, $key);

// Skip if cache exists.
if (!empty($cache)) {
continue;
}
public function fetch_component_grades_from_sits(array $modocc): void {
if (!empty($modocc)) {
foreach ($modocc as $occ) {
// Get the cache.
$key = implode('_',
[
cachemanager::CACHE_AREA_COMPONENTGRADES,
$occ->mod_code,
$occ->mod_occ_mav,
$occ->mod_occ_psl_code,
$occ->mod_occ_year_code,
]
);

// Replace '/' with '_' for simple key.
$key = str_replace('/', '_', $key);

// This cache is not really used.
// It is only used to check if the component grades have been fetched for this module occurrence.
$cache = cachemanager::get_cache(cachemanager::CACHE_AREA_COMPONENTGRADES, $key);

// Skip if cache exists.
if (!empty($cache)) {
continue;
}

try {
// Get component grades from SITS.
$request = $this->apiclient->build_request(self::GET_COMPONENT_GRADE, $occ);
$response = $this->apiclient->send_request($request);
Expand All @@ -179,20 +179,16 @@ public function fetch_component_grades_from_sits(array $modocc): bool {
// Filter out unwanted component grades by marking scheme.
$response = $this->filter_out_invalid_component_grades($response);

// Set cache expiry to 30 days.
cachemanager::set_cache(cachemanager::CACHE_AREA_COMPONENTGRADES, $key, $response, 30 * 24 * 60 * 60);
// Set cache expiry to 1 hour.
cachemanager::set_cache(cachemanager::CACHE_AREA_COMPONENTGRADES, $key, $response, 3600);

// Save component grades to DB.
$this->save_component_grades($response);
} catch (\moodle_exception $e) {
$this->apierrors[] = $e->getMessage();
}

return true;
}
} catch (\moodle_exception $e) {
$this->apierrors[] = $e->getMessage();
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$plugin->component = 'local_sitsgradepush';
$plugin->release = '0.1.0';
$plugin->version = 2024020100;
$plugin->requires = 2023100900;
$plugin->requires = 2021051708;
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = [
'block_portico_enrolments' => 2023012400,
Expand Down

0 comments on commit 725a701

Please sign in to comment.