Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Verified Commit 2533038f authored by David Beniamine's avatar David Beniamine
Browse files

Fix activity deletion

parent 9596a2d0
......@@ -83,7 +83,7 @@ class fetcher
$response = \curl_exec($curl);
if (\curl_errno($curl) !== 0) {
$this->lastError = (object) [
'code' => 0,
'code' => \curl_getinfo($ch, CURLINFO_HTTP_CODE),
'message' => \curl_error($curl),
];
}
......
......@@ -72,4 +72,13 @@ class institution extends moodlefetcher
global $CFG;
return $CFG->labnbook_api_key;
}
/**
* deletes a teamconfig
* @return boolean
*/
public function deleteTeamconfig($teamconfigId)
{
return $this->fetch('POST', '/v1/teamconfig/'.$teamconfigId.'/delete');
}
}
......@@ -50,15 +50,6 @@ class user extends moodlefetcher
return $this->fetch('GET', '/v1/teamconfig/'.$teamconfigId.'/countStartedReports');
}
/**
* deletes a teamconfig
* @return boolean
*/
public function deleteTeamconfig($teamconfigId)
{
return $this->fetch('POST', '/v1/teamconfig/'.$teamconfigId.'/delete');
}
/**
* Give a teacher a tutor access to these LnB missions and classes, if it does not exist yet.
*
......
......@@ -143,14 +143,18 @@ function labnbook_delete_instance($id)
$record = $DB->get_record(LABNBOOK_TABLE, ['id' => $id]);
if (!$record) {
return false;
return true;
}
try {
$fetcher = new fetch\institution();
$fetcher->deleteTeamconfig($record->labnbook_teamconfigid);
} catch(\Exception $e) {
$error = $fetcher->getLastError();
// 404 means already removed in this case, we just ignore the error
if ($error->code != 404) {
throw $e;
}
$fetcher = new fetch\user();
if (!$fetcher->deleteTeamconfig($record->labnbook_teamconfigid)) {
throw new moodle_exception("Cannot delete teamconfig : some students have started to work.");
return false;
}
$DB->delete_records(LABNBOOK_TABLE, ['id' => $id]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment