Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LabNbook
LabNbook-Moodle
Commits
2533038f
Verified
Commit
2533038f
authored
Jun 18, 2020
by
David Beniamine
Browse files
Fix activity deletion
parent
9596a2d0
Changes
4
Hide whitespace changes
Inline
Side-by-side
classes/fetch/fetcher.php
View file @
2533038f
...
...
@@ -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
),
];
}
...
...
classes/fetch/institution.php
View file @
2533038f
...
...
@@ -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'
);
}
}
classes/fetch/user.php
View file @
2533038f
...
...
@@ -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.
*
...
...
lib.php
View file @
2533038f
...
...
@@ -143,14 +143,18 @@ function labnbook_delete_instance($id)
$record
=
$DB
->
get_record
(
LABNBOOK_TABLE
,
[
'id'
=>
$id
]);
if
(
!
$record
)
{
return
fals
e
;
return
tru
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
;
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
;
}
}
$DB
->
delete_records
(
LABNBOOK_TABLE
,
[
'id'
=>
$id
]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment