Permalink
Browse files

Merge pull request #2731 from forkcms/cleanup

Cleanup
  • Loading branch information...
carakas committed Jan 31, 2019
2 parents 742bb6b + c5c617f commit e14bafbd8a62226de116ebe8777450b83eb5e627
Showing with 363 additions and 337 deletions.
  1. +2 −1 src/Backend/Core/Engine/FormImage.php
  2. +3 −3 src/Backend/Core/Engine/Model.php
  3. +4 −5 src/Backend/Core/Engine/Url.php
  4. +33 −21 src/Backend/Modules/Blog/Actions/Edit.php
  5. +19 −39 src/Backend/Modules/Blog/Engine/Model.php
  6. +1 −1 src/Backend/Modules/Blog/Tests/Actions/EditTest.php
  7. +11 −11 src/Backend/Modules/ContentBlocks/Domain/ContentBlock/ContentBlockDataTransferObject.php
  8. +0 −1 src/Backend/Modules/Extensions/Actions/DetailModule.php
  9. +19 −15 src/Backend/Modules/Extensions/Actions/UploadModule.php
  10. +1 −1 src/Backend/Modules/Extensions/Actions/UploadTheme.php
  11. +29 −26 src/Backend/Modules/Extensions/Installer/Installer.php
  12. +35 −14 src/Backend/Modules/Locale/Actions/Add.php
  13. +28 −26 src/Backend/Modules/Locale/Actions/Import.php
  14. +1 −1 src/Backend/Modules/Location/Engine/Model.php
  15. +2 −2 src/Backend/Modules/Mailmotor/EventListener/SettingsSavedListener.php
  16. +1 −1 src/Backend/Modules/MediaLibrary/Actions/MediaBrowser.php
  17. +1 −2 src/Backend/Modules/MediaLibrary/Actions/MediaItemUpload.php
  18. +1 −1 src/Backend/Modules/MediaLibrary/Ajax/MediaFolderEdit.php
  19. +1 −1 src/Backend/Modules/MediaLibrary/Ajax/MediaItemGetAllById.php
  20. +3 −6 src/Backend/Modules/MediaLibrary/Ajax/MediaItemUpload.php
  21. +2 −2 src/Backend/Modules/MediaLibrary/Domain/MediaItem/MediaItemSelectionDataGrid.php
  22. +3 −3 src/Backend/Modules/Pages/Actions/Add.php
  23. +2 −1 src/Backend/Modules/Pages/Actions/Edit.php
  24. +1 −1 src/Backend/Modules/Pages/Engine/Model.php
  25. +69 −69 src/Backend/Modules/Pages/Installer/Data/locale.xml
  26. +42 −42 src/Backend/Modules/Profiles/Installer/Installer.php
  27. +3 −0 src/Backend/Modules/Settings/Actions/Index.php
  28. +1 −7 src/Backend/Modules/Users/Actions/Edit.php
  29. +2 −2 src/Common/Doctrine/Type/UTCDateTimeType.php
  30. +2 −2 src/Common/Doctrine/Type/UTCTimeType.php
  31. +4 −3 src/Common/Doctrine/ValueObject/AbstractImage.php
  32. +1 −1 src/Common/Mailer/Message.php
  33. +1 −1 src/Console/Locale/EnableLocaleCommand.php
  34. +1 −1 src/ForkCMS/Bundle/InstallerBundle/Controller/InstallerController.php
  35. +4 −5 src/Frontend/Core/Engine/Ajax.php
  36. +1 −1 src/Frontend/Core/Engine/Footer.php
  37. +6 −2 src/Frontend/Core/Engine/FormEndTokenParser.php
  38. +1 −1 src/Frontend/Core/Engine/FormFieldErrorTokenParser.php
  39. +1 −1 src/Frontend/Core/Engine/FormFieldTokenParser.php
  40. +2 −1 src/Frontend/Core/Engine/FormImage.php
  41. +1 −1 src/Frontend/Core/Engine/Model.php
  42. +6 −2 src/Frontend/Core/Engine/SeoFormTokenParser.php
  43. +7 −6 src/Frontend/Modules/Blog/Engine/Model.php
  44. +1 −1 src/Frontend/Modules/FormBuilder/EventListener/FormBuilderSubmittedMailSubscriber.php
  45. +1 −1 src/Frontend/Modules/MediaLibrary/Widgets/OneImage.php
  46. +1 −1 src/Frontend/Modules/Profiles/Actions/Activate.php
  47. +2 −1 src/Frontend/Modules/Profiles/Actions/Settings.php
@@ -2,6 +2,7 @@
namespace Backend\Core\Engine;
use ForkCMS\Utility\Thumbnails;
use SpoonFilter;
use SpoonFormImage;
use Symfony\Component\Filesystem\Filesystem;
@@ -59,7 +60,7 @@ public function generateThumbnails($path, $filename): void
$this->moveFile($path . '/source/' . $filename);
// generate the thumbnails
Model::generateThumbnails($path, $path . '/source/' . $filename);
Model::get(Thumbnails::class)->generate($path, $path . '/source/' . $filename);
}
/**
@@ -865,7 +865,7 @@ public static function submitSpam(
*
* @param int $id The id for the extra.
* @param string $key The key you want to update.
* @param string|array $value The new value.
* @param mixed $value The new value.
*
* @throws Exception If key parameter is not allowed
*/
@@ -899,14 +899,14 @@ public static function updateExtraData(int $id, string $key, $value): void
{
$database = self::getContainer()->get('database');
$data = (string) $database->getVar(
$serializedData = (string) $database->getVar(
'SELECT i.data
FROM modules_extras AS i
WHERE i.id = ?',
[$id]
);
$data = $data === null ? [] : unserialize($data);
$data = empty($serializedData) ? [] : unserialize($serializedData);
$data[$key] = $value;
$database->update('modules_extras', ['data' => serialize($data)], 'id = ?', [$id]);
}
@@ -333,6 +333,10 @@ public function getAction(): string
public function getModule(): string
{
if ($this->module === null) {
throw new Exception('Module has not yet been set.');
}
return $this->module;
}
@@ -343,11 +347,6 @@ private function setAction(string $action, string $module = null): void
$this->setModule($module);
}
// check if module is set
if ($this->getModule() === null) {
throw new Exception('Module has not yet been set.');
}
// is this action allowed?
if (!Authentication::isAllowedAction($action, $this->getModule())) {
// set correct headers
@@ -3,6 +3,7 @@
namespace Backend\Modules\Blog\Actions;
use Backend\Modules\Blog\Form\BlogDeleteType;
use ForkCMS\Utility\Thumbnails;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Backend\Core\Engine\Base\ActionEdit as BackendBaseActionEdit;
@@ -389,7 +390,7 @@ private function validateForm(): void
// only copy if the new name differs from the old filename
if (preg_replace($regex, '$1', $newName) != preg_replace($regex, '$1', $item['image'])) {
// loop folders
foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) {
foreach ($this->get(Thumbnails::class)->getFolders($imagePath, true) as $folder) {
$filesystem->copy($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName);
}
@@ -414,38 +415,49 @@ private function validateForm(): void
$this->url->getModule()
);
// active
if ($item['status'] == 'active') {
if ($item['status'] === 'active') {
// edit search index
BackendSearchModel::saveIndex(
$this->getModule(),
$item['id'],
['title' => $item['title'], 'text' => $item['text']]
);
// build URL
$redirectUrl = BackendModel::createUrlForAction('Index') .
'&report=edited&var=' . rawurlencode($item['title']) .
'&id=' . $this->id . '&highlight=row-' . $item['revision_id'];
} elseif ($item['status'] == 'draft') {
// draft: everything is saved, so redirect to the edit action
$redirectUrl = BackendModel::createUrlForAction('Edit') .
'&report=saved-as-draft&var=' . rawurlencode($item['title']) .
'&id=' . $item['id'] . '&draft=' . $item['revision_id'] .
'&highlight=row-' . $item['revision_id'];
}
// append to redirect URL
if ($this->categoryId != null) {
$redirectUrl .= '&category=' . $this->categoryId;
}
// everything is saved, so redirect to the overview
$this->redirect($redirectUrl);
$this->redirect($this->getRedirectUrl($item));
}
}
}
private function getRedirectUrl(array $blogPost): string
{
$redirectAction = 'Index';
$parameters = [
'id' => $blogPost['id'],
'highlight=row' => $blogPost['revision_id'],
'var' => $blogPost['title'],
'report' => 'edited',
];
if ($this->categoryId !== null) {
$parameters['category'] = $this->categoryId;
}
if ($blogPost['status'] === 'draft') {
$redirectAction = 'Edit';
$parameters['report'] = 'saved-as-draft';
$parameters['draft'] = $blogPost['revision_id'];
}
return BackendModel::createUrlForAction($redirectAction) . '&' . http_build_query(
$parameters,
null,
'&',
PHP_QUERY_RFC3986
);
}
private function loadDeleteForm(): void
{
$deleteForm = $this->createForm(
@@ -7,6 +7,7 @@
use Backend\Core\Engine\Model as BackendModel;
use Backend\Core\Language\Language as BL;
use Backend\Modules\Tags\Engine\Model as BackendTagsModel;
use ForkCMS\Utility\Thumbnails;
/**
* In this file we store all generic functions that we will be using in the blog module
@@ -168,7 +169,7 @@ public static function delete($ids): void
$images = $database->getColumn('SELECT image FROM blog_posts WHERE id IN (' . $idPlaceHolders . ')', $ids);
foreach ($images as $image) {
BackendModel::deleteThumbnails(FRONTEND_FILES_PATH . '/Blog/images', $image);
BackendModel::get(Thumbnails::class)->delete(FRONTEND_FILES_PATH . '/Blog/images', $image);
}
// delete records
@@ -353,34 +354,13 @@ public static function get(int $id): array
* Get the comments
*
* @param string $status The type of comments to get.
* @param int $limit The maximum number of items to retrieve.
* @param int $offset The offset.
* @param int $limit The maximum number of items to retrieve.
* @param int $offset The offset.
*
* @return array
*/
public static function getAllCommentsForStatus(string $status, int $limit = 30, int $offset = 0): array
{
if ($status !== null) {
$status = (string) $status;
}
$limit = (int) $limit;
$offset = (int) $offset;
// no status passed
if ($status === null) {
return (array) BackendModel::getContainer()->get('database')->getRecords(
'SELECT i.id, UNIX_TIMESTAMP(i.created_on) AS created_on, i.author, i.email, i.website, i.text, i.type, i.status,
p.id AS post_id, p.title AS post_title, m.url AS post_url, p.language AS post_language
FROM blog_comments AS i
INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
INNER JOIN meta AS m ON p.meta_id = m.id
WHERE i.language = ?
GROUP BY i.id
LIMIT ?, ?',
[BL::getWorkingLanguage(), $offset, $limit]
);
}
return (array) BackendModel::getContainer()->get('database')->getRecords(
'SELECT i.id, UNIX_TIMESTAMP(i.created_on) AS created_on, i.author, i.email, i.website, i.text, i.type, i.status,
p.id AS post_id, p.title AS post_title, m.url AS post_url, p.language AS post_language
@@ -470,7 +450,7 @@ public static function getCategory($id): array
/**
* Get a category id by title
*
* @param string $title The title of the category.
* @param string $title The title of the category.
* @param string $language The language to use, if not provided we will use the working language.
*
* @return int
@@ -546,7 +526,7 @@ public static function getCommentStatusCount(): array
* Get the latest comments for a given type
*
* @param string $status The status for the comments to retrieve.
* @param int $limit The maximum number of items to retrieve.
* @param int $limit The maximum number of items to retrieve.
*
* @return array
*/
@@ -588,7 +568,7 @@ public static function getMaximumId(): int
/**
* Get all data for a given revision
*
* @param int $id The id of the item.
* @param int $id The id of the item.
* @param int $revisionId The revision to get.
*
* @return array
@@ -608,7 +588,7 @@ public static function getRevision(int $id, int $revisionId): array
* Retrieve the unique URL for an item
*
* @param string $url The URL to base on.
* @param int $id The id of the item to ignore.
* @param int $id The id of the item to ignore.
*
* @return string
*/
@@ -659,7 +639,7 @@ public static function getUrl(string $url, int $id = null): string
* Retrieve the unique URL for a category
*
* @param string $url The string whereon the URL will be based.
* @param int $id The id of the category to ignore.
* @param int $id The id of the category to ignore.
*
* @return string
*/
@@ -736,9 +716,9 @@ public static function insert(array $item): int
* The comments array is an array of arrays with comment properties. A comment should have
* at least 'author', 'email', and 'text' properties.
*
* @param array $item The data to insert.
* @param array $meta The metadata to insert.
* @param array $tags The tags to connect to this post.
* @param array $item The data to insert.
* @param array $meta The metadata to insert.
* @param array $tags The tags to connect to this post.
* @param array $comments The comments attached to this post.
*
* @throws Exception
@@ -792,9 +772,6 @@ public static function insertCompletePost(array $item, array $meta = [], $tags =
}
// Build meta
if (!is_array($meta)) {
$meta = [];
}
if (!isset($meta['keywords'])) {
$meta['keywords'] = $item['title'];
}
@@ -1060,8 +1037,11 @@ public static function update(array $item): int
// make sure that an image that will be deleted, is not used by a revision that is not to be deleted
foreach ($imagesOfDeletedRevisions as $imageOfDeletedRevision) {
if (!in_array($imageOfDeletedRevision, $imagesToKeep)) {
BackendModel::deleteThumbnails(FRONTEND_FILES_PATH . '/Blog/images', $imageOfDeletedRevision);
if (!in_array($imageOfDeletedRevision, $imagesToKeep, true)) {
BackendModel::get(Thumbnails::class)->delete(
FRONTEND_FILES_PATH . '/Blog/images',
$imageOfDeletedRevision
);
}
}
@@ -1089,7 +1069,7 @@ public static function update(array $item): int
/**
* Update an existing category
*
* @param array $item The new data.
* @param array $item The new data.
* @param array $meta The new meta-data.
*
* @return int
@@ -1135,7 +1115,7 @@ public static function updateComment(array $item): int
/**
* Updates one or more comments' status
*
* @param array $ids The id(s) of the comment(s) to change the status for.
* @param array $ids The id(s) of the comment(s) to change the status for.
* @param string $status The new status.
*/
public static function updateCommentStatuses(array $ids, string $status): void
@@ -76,7 +76,7 @@ public function testEditingOurBlogPost(): void
// our url and our page should contain the new title of our blogpost
self::assertContains(
'&report=edited&var=Edited%20blogpost%20for%20functional%20tests&id=1',
'&id=1&highlight%3Drow=2&var=Edited%20blogpost%20for%20functional%20tests&report=edited',
$client->getHistory()->current()->getUri()
);
self::assertContains(
@@ -78,19 +78,19 @@ public function __construct(ContentBlock $contentBlock = null)
return;
}
$this->id = $contentBlock->getId();
$this->extraId = $contentBlock->getExtraId();
$this->isVisible = !$contentBlock->isHidden();
$this->title = $contentBlock->getTitle();
$this->text = $contentBlock->getText();
$this->template = $contentBlock->getTemplate();
$this->userId = $contentBlock->getUserId();
$this->locale = $contentBlock->getLocale();
$this->status = $contentBlock->getStatus();
$this->revisionId = $contentBlock->getRevisionId();
$this->id = $this->contentBlockEntity->getId();
$this->extraId = $this->contentBlockEntity->getExtraId();
$this->isVisible = !$this->contentBlockEntity->isHidden();
$this->title = $this->contentBlockEntity->getTitle();
$this->text = $this->contentBlockEntity->getText();
$this->template = $this->contentBlockEntity->getTemplate();
$this->userId = $this->contentBlockEntity->getUserId();
$this->locale = $this->contentBlockEntity->getLocale();
$this->status = $this->contentBlockEntity->getStatus();
$this->revisionId = $this->contentBlockEntity->getRevisionId();
}
public function forOtherLocale(int $id, int $extraId, Locale $locale)
public function forOtherLocale(int $id, int $extraId, Locale $locale): void
{
$this->id = $id;
$this->contentBlockEntity = null;
@@ -26,7 +26,6 @@ class DetailModule extends BackendBaseActionIndex
*
* @var BackendDataGridArray
*/
private $dataGridCronjobs;
private $dataGridEvents;
/**
@@ -225,22 +225,26 @@ private function buildForm(): void
private function validateForm(): void
{
// the form is submitted
if ($this->form->isSubmitted()) {
// shorten field variables
$fileFile = $this->form->getField('file');
// validate the file
if ($fileFile->isFilled(BL::err('FieldIsRequired')) && $fileFile->isAllowedExtension(['zip'], sprintf(BL::getError('ExtensionNotAllowed'), 'zip'))) {
$moduleName = $this->uploadModuleFromZip();
}
if (!$this->form->isSubmitted()) {
return;
}
// passed all validation
if ($this->form->isCorrect()) {
// redirect to the install url, this is needed for doctrine modules because the container needs to
// load this module as an allowed module to get the entities working
$this->redirect(BackendModel::createUrlForAction('InstallModule') . '&module=' . $moduleName);
}
// shorten field variables
$fileFile = $this->form->getField('file');
// validate the file
$fileFile->isFilled(BL::err('FieldIsRequired'));
$fileFile->isAllowedExtension(['zip'], sprintf(BL::getError('ExtensionNotAllowed'), 'zip'));
// passed all validation
if (!$this->form->isCorrect()) {
return;
}
$moduleName = $this->uploadModuleFromZip();
// redirect to the install url, this is needed for doctrine modules because the container needs to
// load this module as an allowed module to get the entities working
$this->redirect(BackendModel::createUrlForAction('InstallModule') . '&module=' . $moduleName);
}
}
Oops, something went wrong.

0 comments on commit e14bafb

Please sign in to comment.