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
......@@ -10,6 +10,7 @@ namespace qfq;
require_once(__DIR__ . '/Constants.php');
require_once(__DIR__ . '/Database.php');
require_once(__DIR__ . '/store/Store.php');
class Delete {
......@@ -18,11 +19,17 @@ class Delete {
*/
private $db = null;
/**
* @var Store
*/
private $store = null;
/**
*
*/
public function __construct() {
public function __construct($phpUnit = false) {
$this->db = new Database();
$this->store = Store::getInstance('', $phpUnit);
}
/**
......@@ -36,6 +43,7 @@ class Delete {
* @return bool
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public function process(array $form, $recordId, array &$msg) {
$rc = false;
......@@ -49,6 +57,13 @@ class Delete {
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.
$row = $this->db->sql("SELECT * FROM " . $form[F_TABLE_NAME] . " WHERE id=?", ROW_EXPECT_0_1, [$recordId]);
if (count($row) > 0) {
......@@ -83,6 +98,8 @@ class Delete {
$msg[MSG_ERROR_CODE] = ERROR_RECORD_NOT_FOUND;
}
chdir($cwd);
return $rc;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment