FEATURE #2472: fix few minor bugs in template management
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Templates;
|
||||
|
||||
use App\Cms\Repositories\Templates\Template as TemplateRepository;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\CopyTemplateRequest;
|
||||
use App\Models\Templates\Template;
|
||||
@@ -10,7 +11,6 @@ class CopyTemplate extends Controller
|
||||
{
|
||||
/**
|
||||
* Method for copying given template.
|
||||
*
|
||||
* This method is supposed to be called by POST method.
|
||||
*
|
||||
* @param CopyTemplateRequest $request
|
||||
@@ -32,15 +32,22 @@ class CopyTemplate extends Controller
|
||||
$namespace .= '::';
|
||||
}
|
||||
|
||||
$repository = app(TemplateRepository::class);
|
||||
$repository->setModel($template);
|
||||
|
||||
// get template absolute paths
|
||||
$realTemplatePath = $template->getPathToTemplate();
|
||||
$customTemplatePath = $template->getPathToTemplate(Template::CUSTOM_EDIT_DIRECTORY);
|
||||
$realTemplatePath = $repository->getPathToTemplate();
|
||||
$customTemplatePath = $repository->getPathToTemplate(TemplateRepository::CUSTOM_EDIT_DIRECTORY);
|
||||
$path = dirname($customTemplatePath);
|
||||
|
||||
// create file copy
|
||||
$data = file_get_contents($realTemplatePath);
|
||||
$written = file_put_contents($path . DIRECTORY_SEPARATOR . $newName . Template::TEMPLATE_SUFFIX, $data);
|
||||
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
|
||||
$written = file_put_contents($path . DIRECTORY_SEPARATOR . $newName . TemplateRepository::TEMPLATE_SUFFIX, $data);
|
||||
// were data written?
|
||||
if ($written === false) {
|
||||
return $this->copyFailed($request, $template);
|
||||
@@ -67,7 +74,6 @@ class CopyTemplate extends Controller
|
||||
* @param Template $template
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||
*
|
||||
*/
|
||||
private function copyFailed(CopyTemplateRequest $request, Template $template)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user