Completed
Push — stable9 ( 485cb1...e094cf )
by Lukas
26:41 queued 26:23
created

apps/files_trashbin/ajax/undelete.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Björn Schießle <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 * @author Robin Appelman <[email protected]>
9
 * @author Roeland Jago Douma <[email protected]>
10
 * @author Thomas Müller <[email protected]>
11
 * @author Vincent Petry <[email protected]>
12
 *
13
 * @license AGPL-3.0
14
 *
15
 * This code is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License, version 3,
17
 * as published by the Free Software Foundation.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License, version 3,
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
26
 *
27
 */
28
OCP\JSON::checkLoggedIn();
0 ignored issues
show
Deprecated Code introduced by
The method OCP\JSON::checkLoggedIn() has been deprecated with message: 8.1.0 Use annotation based ACLs from the AppFramework instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
29
OCP\JSON::callCheck();
0 ignored issues
show
Deprecated Code introduced by
The method OCP\JSON::callCheck() has been deprecated with message: 8.1.0 Use annotation based CSRF checks from the AppFramework instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
30
\OC::$server->getSession()->close();
31
32
$dir = '/';
33
if (isset($_POST['dir'])) {
34
	$dir = rtrim((string)$_POST['dir'], '/'). '/';
35
}
36
$allFiles = false;
37
if (isset($_POST['allfiles']) && (string)$_POST['allfiles'] === 'true') {
38
	$allFiles = true;
39
	$list = array();
40
	$dirListing = true;
41
	if ($dir === '' || $dir === '/') {
42
		$dirListing = false;
43
	}
44
	foreach (OCA\Files_Trashbin\Helper::getTrashFiles($dir, \OCP\User::getUser()) as $file) {
45
		$fileName = $file['name'];
46
		if (!$dirListing) {
47
			$fileName .= '.d' . $file['mtime'];
48
		}
49
		$list[] = $fileName;
50
	}
51
} else {
52
	$list = json_decode($_POST['files']);
53
}
54
55
$error = array();
56
$success = array();
57
58
$i = 0;
59
foreach ($list as $file) {
60
	$path = $dir . '/' . $file;
61 View Code Duplication
	if ($dir === '/') {
62
		$file = ltrim($file, '/');
63
		$delimiter = strrpos($file, '.d');
64
		$filename = substr($file, 0, $delimiter);
65
		$timestamp =  substr($file, $delimiter+2);
66
	} else {
67
		$path_parts = pathinfo($file);
68
		$filename = $path_parts['basename'];
69
		$timestamp = null;
70
	}
71
72 View Code Duplication
	if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) {
73
		$error[] = $filename;
74
		\OCP\Util::writeLog('trashbin', 'can\'t restore ' . $filename, \OCP\Util::ERROR);
75
	} else {
76
		$success[$i]['filename'] = $file;
77
		$success[$i]['timestamp'] = $timestamp;
78
		$i++;
79
	}
80
81
}
82
83 View Code Duplication
if ( $error ) {
84
	$filelist = '';
85
	foreach ( $error as $e ) {
86
		$filelist .= $e.', ';
87
	}
88
	$l = OC::$server->getL10N('files_trashbin');
89
	$message = $l->t("Couldn't restore %s", array(rtrim($filelist, ', ')));
90
	OCP\JSON::error(array("data" => array("message" => $message,
0 ignored issues
show
Deprecated Code introduced by
The method OCP\JSON::error() has been deprecated with message: 8.1.0 Use a AppFramework JSONResponse instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
91
										  "success" => $success, "error" => $error)));
92
} else {
93
	OCP\JSON::success(array("data" => array("success" => $success)));
0 ignored issues
show
Deprecated Code introduced by
The method OCP\JSON::success() has been deprecated with message: 8.1.0 Use a AppFramework JSONResponse instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
94
}
95