Skip to content
Snippets Groups Projects
Commit a1cc0200 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Delete: fixed that files not automatically deleted.

Delete.php: chdir to the correct directory before starting to delete files
parent 9efd27f5
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ namespace qfq; ...@@ -10,6 +10,7 @@ namespace qfq;
require_once(__DIR__ . '/Constants.php'); require_once(__DIR__ . '/Constants.php');
require_once(__DIR__ . '/Database.php'); require_once(__DIR__ . '/Database.php');
require_once(__DIR__ . '/store/Store.php');
class Delete { class Delete {
...@@ -18,11 +19,17 @@ class Delete { ...@@ -18,11 +19,17 @@ class Delete {
*/ */
private $db = null; private $db = null;
/**
* @var Store
*/
private $store = null;
/** /**
* *
*/ */
public function __construct() { public function __construct($phpUnit = false) {
$this->db = new Database(); $this->db = new Database();
$this->store = Store::getInstance('', $phpUnit);
} }
/** /**
...@@ -36,6 +43,7 @@ class Delete { ...@@ -36,6 +43,7 @@ class Delete {
* @return bool * @return bool
* @throws CodeException * @throws CodeException
* @throws DbException * @throws DbException
* @throws UserFormException
*/ */
public function process(array $form, $recordId, array &$msg) { public function process(array $form, $recordId, array &$msg) {
$rc = false; $rc = false;
...@@ -49,6 +57,13 @@ class Delete { ...@@ -49,6 +57,13 @@ class Delete {
throw new CodeException('Invalid record id', ERROR_MISSING_RECORD_ID); throw new CodeException('Invalid record id', ERROR_MISSING_RECORD_ID);
} }
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !chdir($sitePath)) {
throw new UserFormException("getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed.", ERROR_IO_CHDIR);
}
// Read record first. // Read record first.
$row = $this->db->sql("SELECT * FROM " . $form[F_TABLE_NAME] . " WHERE id=?", ROW_EXPECT_0_1, [$recordId]); $row = $this->db->sql("SELECT * FROM " . $form[F_TABLE_NAME] . " WHERE id=?", ROW_EXPECT_0_1, [$recordId]);
if (count($row) > 0) { if (count($row) > 0) {
...@@ -83,6 +98,8 @@ class Delete { ...@@ -83,6 +98,8 @@ class Delete {
$msg[MSG_ERROR_CODE] = ERROR_RECORD_NOT_FOUND; $msg[MSG_ERROR_CODE] = ERROR_RECORD_NOT_FOUND;
} }
chdir($cwd);
return $rc; return $rc;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment