mirror of
https://github.com/typemill/typemill.git
synced 2025-07-31 11:20:15 +02:00
improve delete folder
This commit is contained in:
@@ -103,17 +103,19 @@
|
||||
* Clear cache
|
||||
* Show security Log
|
||||
* User search only for +10 users
|
||||
* fix error messages
|
||||
* DONE: fix error messages (check models)
|
||||
* DONE: error status codes (check middleware)
|
||||
* Wrong frontend navigation if unpublished pages
|
||||
* Customfields not styled yet.
|
||||
* Warn if open another block
|
||||
* finish youtube component
|
||||
* Solution for logo and favicon
|
||||
* For api translations should be done completely in backoffice
|
||||
|
||||
## Cleanups:
|
||||
|
||||
* DONE: Events
|
||||
* Error messages
|
||||
* DONE: Error messages
|
||||
* Translations
|
||||
* https://stackoverflow.com/questions/15041608/searching-all-files-in-folder-for-strings
|
||||
* https://github.com/skfaisal93/AnyWhereInFiles/blob/master/anywhereinfiles-1.4.php
|
||||
|
@@ -641,7 +641,6 @@ class ControllerApiAuthorArticle extends Controller
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
|
||||
public function renameArticle(Request $request, Response $response, $args)
|
||||
{
|
||||
$validRights = $this->validateRights($request->getAttribute('c_userrole'), 'mycontent', 'edit');
|
||||
@@ -902,7 +901,15 @@ class ControllerApiAuthorArticle extends Controller
|
||||
# check if it is a folder and if the folder has published pages.
|
||||
if($item->elementType == 'folder')
|
||||
{
|
||||
$result = $content->deleteFolder($item);
|
||||
# check if folder has published pages
|
||||
if($content->hasPublishedItems($item))
|
||||
{
|
||||
$result = Translations::translate('The folder contains published pages. Please unpublish or delete them first.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $content->deleteFolder($item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -21,7 +21,6 @@ class ApiAuthorization implements MiddlewareInterface
|
||||
{
|
||||
if(!$this->acl->isAllowed($request->getAttribute('c_userrole'), $this->resource, $this->action))
|
||||
{
|
||||
|
||||
$message = 'userrole: ' . $request->getAttribute('c_userrole') . ' resource: ' . $this->resource . ' action: ' . $this->action;
|
||||
$response = new Response();
|
||||
|
||||
@@ -29,7 +28,7 @@ class ApiAuthorization implements MiddlewareInterface
|
||||
'message' => $message
|
||||
]));
|
||||
|
||||
return $response->withStatus(401);
|
||||
return $response->withStatus(403);
|
||||
}
|
||||
|
||||
$response = $handler->handle($request);
|
||||
|
@@ -130,65 +130,18 @@ class Content
|
||||
return true;
|
||||
}
|
||||
|
||||
# overcomplicated. Next time just use a recursive delete everything method in storage
|
||||
public function deleteFolder($item, $result = true)
|
||||
{
|
||||
if($item->elementType == 'folder' && isset($item->folderContent) && is_array($item->folderContent) && !empty($item->folderContent))
|
||||
if($this->storage->deleteContentFolderRecursive($item->path))
|
||||
{
|
||||
if($this->hasPublishedItems($item))
|
||||
{
|
||||
return 'The folder contains published pages. Please unpublish or delete them first.';
|
||||
}
|
||||
|
||||
foreach($item->folderContent as $subitem)
|
||||
{
|
||||
if($subitem->elementType == 'folder')
|
||||
{
|
||||
$result = $this->deleteFolder($subitem);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->deletePage($subitem);
|
||||
}
|
||||
|
||||
if($result !== true)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->deletePage($item);
|
||||
|
||||
if($result !== true)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = $this->storage->deleteContentFolder($item->path);
|
||||
|
||||
if($result !== true)
|
||||
{
|
||||
return $this->storage->getError();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$result = $this->deletePage($item);
|
||||
|
||||
if($result !== true)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = $this->storage->deleteContentFolder($item->path);
|
||||
|
||||
if($result !== true)
|
||||
{
|
||||
return $this->storage->getError();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return $this->storage->getError();
|
||||
}
|
||||
|
||||
private function hasPublishedItems($folder, $published = false)
|
||||
public function hasPublishedItems($folder, $published = false)
|
||||
{
|
||||
$published = false;
|
||||
|
||||
|
@@ -203,6 +203,48 @@ class Storage
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteContentFolderRecursive($folderpath)
|
||||
{
|
||||
$folderdir = $this->getFolderPath('contentFolder');
|
||||
|
||||
if(!is_dir($folderdir . $folderpath))
|
||||
{
|
||||
$this->error = "$folderpath is not a directory";
|
||||
return false;
|
||||
}
|
||||
|
||||
$filelist = array_diff(scandir($folderdir . $folderpath), array('..', '.'));
|
||||
if(!empty($filelist))
|
||||
{
|
||||
foreach($filelist as $filepath)
|
||||
{
|
||||
$fullfilepath = $folderdir . $folderpath . DIRECTORY_SEPARATOR . $filepath;
|
||||
if(is_dir($fullfilepath))
|
||||
{
|
||||
$this->deleteContentFolderRecursive($folderpath . DIRECTORY_SEPARATOR . $filepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!unlink($fullfilepath))
|
||||
{
|
||||
$this->error = "Could not delete file $fullfilepath.";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!rmdir($folderdir . $folderpath))
|
||||
{
|
||||
$this->error = "Could not delete folder $folderpath.";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkFile($location, $folder, $filename)
|
||||
{
|
||||
$filepath = $this->getFolderPath($location, $folder) . $filename;
|
||||
|
Reference in New Issue
Block a user