Conversation
src/helpers/WidgetTemplateExport.php
Outdated
| // Create the tar archive | ||
| $phar = new \PharData($this->getTarFilePath()); | ||
| // Add generated files | ||
| $phar->addFile($this->getTemplateFilePath(), $this->templateFilename); |
There was a problem hiding this comment.
why not add strings to the tar directly instead of creating/removing tmp-files?
$phar->addFromString($this->templateFilename, $this->widgetTemplate->twig_template);
This would significantly reduce the complexity because we would have much less file handling.
There was a problem hiding this comment.
I have modified the code to meet your requirements. In this move I also removed the methods that create the temporary files.
src/helpers/WidgetTemplateExport.php
Outdated
| * | ||
| * @var string | ||
| */ | ||
| public $exportDirectory = '@runtime/tmp/dmstr/widgets/templates'; |
There was a problem hiding this comment.
directories (and/or filenames) used for such exports should always have some randomness to prevent race conditions.
There was a problem hiding this comment.
This is now a protected property and is set to a random directory in /tmp (via sys_get_temp_dir)
src/models/WidgetTemplateImport.php
Outdated
| } | ||
|
|
||
| // Make sure that if an alias is set, it is resolved correctly | ||
| $this->importDirectory = \Yii::getAlias($this->importDirectory); |
There was a problem hiding this comment.
directories (and/or filenames) used for imports should always have some randomness to prevent race conditions.
There was a problem hiding this comment.
This is now a protected property and is set to a random directory in /tmp (via sys_get_temp_dir)
src/models/WidgetTemplateImport.php
Outdated
| ]); | ||
|
|
||
| if ($model->save() === false) { | ||
| \Yii::error($model->getErrors()); |
There was a problem hiding this comment.
These errors should be passed to the user so that he gets information why the import did not work. (Exceptions?)
see: Line 136
There was a problem hiding this comment.
I've added a custom exceptions. This bundles the error messages that occur when saving. The exception is then caught in the controller and passed on to the user.
src/models/WidgetTemplateImport.php
Outdated
| try { | ||
| FileHelper::removeDirectory($this->importDirectory); | ||
| return true; | ||
| } catch (\ErrorException $e) { |
There was a problem hiding this comment.
yii\base\ErrorException is imported. Is it intended that another ErrorException is used here?
There was a problem hiding this comment.
This line has been removed because it is no longer needed
|
thanks for your work, but we should change file and error handling to:
see comments above. |
|
@handcode : I have updated the code and left explanations to your comments respectively |
| ]); | ||
|
|
||
| if ($model->save() === false) { | ||
| $this->addError('tarFiles', print_r($model->getErrors(), true)); |

Export and import widget templates
This PR provides an export and import functionality for the existing widget template CRUD
Export
Exporting a widget can be done via the newly added export buttons either on the widget template overview page or the widget templates detail page
When exporting a widget template a
.tarfile will be created to summarize the following three files:Import
To import a generated
.tarfile to the db you can do this either from the widget overview (/widget/default/index) page or the widget template overview page. You can either upload one or up to 20.tarfiles (we can still discuss this value. But more makes no sense in my opinion)For each functionality a new permission check was added:
Only if these permissions are granted to the user, the user will be able to see the links and access the corresponding pages.