-
Notifications
You must be signed in to change notification settings - Fork 2
/
Edit.php
81 lines (68 loc) · 1.97 KB
/
Edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
session_start();
require_once 'Globals.php';
require_once 'Environment Interfaces/Session.php';
require_once 'Environment Interfaces/GitHub API/Repositories.php';
if (!isset($_GET['RepositoryId']))
{
http_response_code(400);
return;
}
$RepositoryId = $_GET['RepositoryId'];
if (isset($_POST['Cancel']))
{
SetRedirect(WebURI::Show . '/' . $RepositoryId);
return;
}
$Details = Session::GetLoggedInDetails();
if (!$Details->LoggedIn)
{
SetRedirect(WebURI::Login . '?' . http_build_query(array('login' => 1, 'redirect' => $_SERVER['REQUEST_URI'])));
return;
}
$Query = DB::queryFirstRow(
'SELECT AuthorId, DownloadCount, UpdateHookId, RepositoryName, RepositoryFullName, Description, IconHyperlink
FROM PluginData WHERE RepositoryId = %i',
$RepositoryId
);
if ($Query === null)
{
http_response_code(404);
return;
}
if ($Details->User->AuthorId !== (int)$Query['AuthorId'])
{
http_response_code(403);
return;
}
$Templater = new \Twig\Environment(GetTwigLoader(), GetTwigOptions());
if (isset($_POST['DeleteConfirmed' . $RepositoryId]))
{
// TODO: catch thrown exceptions
// TODO (future proofing): race condition if author ever changes between the check and the delete
GitHubAPI\Repositories::DeleteUpdateHook($RepositoryId, $Query['UpdateHookId']);
DB::delete('PluginData', 'RepositoryId = %i', $RepositoryId);
$Templater->display(
'Immersive Dialog.html',
array(
'Message' => 'Operation successful',
'Explanation' => 'The entry was successfully deleted.',
'LoginDetails' => $Details
)
);
SetRefresh();
return;
}
$Templater->display(
'Immersive Confirmation Dialog.html',
array(
'Message' => 'Plugin deletion confirmation',
'AcceptRedirectLocation' => WebURI::Edit . '/' . $RepositoryId,
'ConfirmationButtonName' => 'DeleteConfirmed' . $RepositoryId,
'LoginDetails' => $Details,
'ContentTemplate' => 'Modules/Delete Plugin Content.html',
'Explanation' => 'This action will reset all ratings and comments. Are you sure?',
'Plugin' => $Query
)
);
?>