18 use Symfony\Component\HttpFoundation\Request;
19 use Symfony\Component\HttpFoundation\Response;
29 const NAME =
"admin_upload_delete";
37 function __construct()
39 parent::__construct(self::NAME, array(
40 self::TITLE => _(
"Delete Uploaded File"),
41 self::MENU_LIST =>
"Organize::Uploads::Delete Uploaded File",
43 self::REQUIRES_LOGIN =>
true
47 $this->uploadDao = $container->get(
'dao.upload');
48 $this->folderDao = $container->get(
'dao.folder');
57 private function delete($uploadpk)
62 $jobpk = JobAddJob($user_pk, $group_pk,
"Delete", $uploadpk);
63 if (empty($jobpk) || ($jobpk < 0)) {
64 return _(
"Failed to create job record");
67 $jqargs =
"DELETE UPLOAD $uploadpk";
68 $jobqueuepk =
JobQueueAdd($jobpk,
"delagent", $jqargs,
null,
null);
69 if (empty($jobqueuepk)) {
70 return _(
"Failed to place delete in job queue");
76 $error_msg = _(
"Is the scheduler running? Your jobs have been added to job queue.");
78 $LinkText = _(
"View Jobs");
79 return "$error_msg <a href=\"$URL\">$LinkText</a>";
88 protected function handle(Request $request)
92 $uploadpks = $request->get(
'uploads');
93 $folderId = $request->get(
'folder');
95 if (!empty($uploadpks)) {
96 $vars[
'message'] = $this->
initDeletion($uploadpks, $folderId);
104 $uploadList = array();
106 foreach ($folderList as $L) {
108 if (!empty($L[
'upload_desc'])) {
109 $desc .=
" (" . $L[
'upload_desc'] .
")";
111 if (!empty($L[
'upload_ts'])) {
112 $desc .=
" :: " . substr($L[
'upload_ts'], 0, 19);
114 $uploadList[$L[
'upload_pk']] = $desc;
116 $vars[
'uploadList'] = $uploadList;
118 return $this->
render(
'admin_upload_delete.html.twig', $this->mergeWithDefault($vars));
130 if (
sizeof($uploadpks) <= 0) {
131 return _(
"No uploads selected");
135 $deleteResponse =
null;
136 foreach ($uploadpks as $uploadPk) {
137 $deleteResponse = $this->
TryToDelete(intval($uploadPk), $folderId);
140 $errorMessages[] = $deleteResponse;
144 if (
sizeof($uploadpks) == 1) {
145 return $deleteResponse->getDeleteMessageString().$deleteResponse->getAdditionalMessage();
148 $displayMessage =
"";
149 $countErrorMessages = array_count_values(array_filter($errorMessages));
151 $displayMessage .=
"<br/>Scheduling failed for " .
156 $displayMessage .=
"No permission to delete " .
160 $displayMessage .=
"Deletion of " .
161 (
sizeof($uploadpks) -
sizeof($errorMessages)) .
" projects queued";
162 return DisplayMessage($displayMessage);
178 if (!empty($this->folderDao->isRemovableContent($uploadpk,2))) {
179 $this->folderDao->removeContentById($uploadpk, $folderId);
183 $rc = $this->
delete(intval($uploadpk));
193 $LinkText = _(
"View Jobs");
196 " <a href=$URL>$LinkText</a>");
200 register_plugin(
new AdminUploadDelete());
Messages which can be generated by delagent.
Handle response from delagent.
UI plugin to delete uploaded files.
initDeletion($uploadpks, $folderId)
starts deletion and handles error messages
TryToDelete($uploadpk, $folderId)
Given a folder_pk, try to add a job after checking permissions.
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static getGroupId()
Get the current user's group id.
render($templateName, $vars=null, $headers=null)
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
GetUserRootFolder()
Get the top-of-tree folder_pk for the current user. Fail if there is no user session.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
Traceback_uri()
Get the URI without query to this location.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
UI namespace for DelAgent.