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 ...@@ -83,7 +83,7 @@ class fetcher
$response = \curl_exec($curl); $response = \curl_exec($curl);
if (\curl_errno($curl) !== 0) { if (\curl_errno($curl) !== 0) {
$this->lastError = (object) [ $this->lastError = (object) [
'code' => 0, 'code' => \curl_getinfo($ch, CURLINFO_HTTP_CODE),
'message' => \curl_error($curl), 'message' => \curl_error($curl),
]; ];
} }
......
...@@ -72,4 +72,13 @@ class institution extends moodlefetcher ...@@ -72,4 +72,13 @@ class institution extends moodlefetcher
global $CFG; global $CFG;
return $CFG->labnbook_api_key; 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 ...@@ -50,15 +50,6 @@ class user extends moodlefetcher
return $this->fetch('GET', '/v1/teamconfig/'.$teamconfigId.'/countStartedReports'); 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. * 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) ...@@ -143,14 +143,18 @@ function labnbook_delete_instance($id)
$record = $DB->get_record(LABNBOOK_TABLE, ['id' => $id]); $record = $DB->get_record(LABNBOOK_TABLE, ['id' => $id]);
if (!$record) { if (!$record) {
return false; return true;
} }
$fetcher = new fetch\user(); try {
if (!$fetcher->deleteTeamconfig($record->labnbook_teamconfigid)) { $fetcher = new fetch\institution();
throw new moodle_exception("Cannot delete teamconfig : some students have started to work."); $fetcher->deleteTeamconfig($record->labnbook_teamconfigid);
return false; } catch(\Exception $e) {
$error = $fetcher->getLastError();
// 404 means already removed in this case, we just ignore the error
if ($error->code != 404) {
throw $e;
}
} }
$DB->delete_records(LABNBOOK_TABLE, ['id' => $id]); $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