Skip to content

Commit

Permalink
Merge pull request #338 from nhovratov/revert-di
Browse files Browse the repository at this point in the history
[!!!] Release 5.1.2
  • Loading branch information
Gernott authored Jul 27, 2020
2 parents 15abded + cf004c4 commit 7c75e7f
Show file tree
Hide file tree
Showing 44 changed files with 680 additions and 617 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### [5.1.2] - 2020-07-21

### Added
- Option to disable phone links. [#336](https://github.com/Gernott/mask/pull/336)

### Changed
- Undone symfony DI change because of breaking changes

### Fixed
- Fields `editlock` and `fe_group` now generated on element save. [#332](https://github.com/nhovratov/mask/commit/fb31c3cc219f8517559318eae2dcc2d3e993bcf2)

### [5.1.1] - 2020-07-15
### Important
- After updating from 5.1.0 or lower, clear the hard caches under Maintenance->Flush cache. Clearing red caches in not enough.
Expand Down
10 changes: 7 additions & 3 deletions Classes/CodeGenerator/AbstractCodeGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace MASK\Mask\CodeGenerator;
Expand Down Expand Up @@ -29,6 +28,7 @@
* ************************************************************* */

use MASK\Mask\Domain\Repository\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Abstract base class for all the other code generators
Expand All @@ -48,9 +48,13 @@ abstract class AbstractCodeGenerator
/**
* @param StorageRepository $storageRepository
*/
public function __construct(StorageRepository $storageRepository)
public function __construct(StorageRepository $storageRepository = null)
{
$this->storageRepository = $storageRepository;
if (!$storageRepository) {
$this->storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
} else {
$this->storageRepository = $storageRepository;
}
}

/**
Expand Down
22 changes: 5 additions & 17 deletions Classes/CodeGenerator/HtmlCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,16 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use MASK\Mask\Domain\Repository\StorageRepository;
use MASK\Mask\Helper\FieldHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Generates the html and fluid for mask content elements
*
* @author Benjamin Butschell <bb@webprofil.at>
*/
class HtmlCodeGenerator
class HtmlCodeGenerator extends AbstractCodeGenerator
{
/**
* StorageRepository
*
* @var StorageRepository
*/
protected $storageRepository;

/**
* @param StorageRepository $storageRepository
*/
public function __construct(StorageRepository $storageRepository)
{
$this->storageRepository = $storageRepository;
}

/**
* Generates Fluid HTML for Contentelements
Expand Down Expand Up @@ -81,7 +68,8 @@ public function generateHtml($key, $table): string
protected function generateFieldHtml($fieldKey, $elementKey, $table, $datafield = 'data'): string
{
$html = '';
switch ($this->storageRepository->getFormType($fieldKey, $elementKey, $table)) {
$fieldHelper = GeneralUtility::makeInstance(FieldHelper::class);
switch ($fieldHelper->getFormType($fieldKey, $elementKey, $table)) {
case 'Check':
$html .= '{f:if(condition: ' . $datafield . '.' . $fieldKey . ", then: 'On', else: 'Off')}<br />\n\n";
break;
Expand Down
39 changes: 39 additions & 0 deletions Classes/CodeGenerator/JsonCodeGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

namespace MASK\Mask\CodeGenerator;

/* * *************************************************************
* Copyright notice
*
* (c) 2016 Benjamin Butschell <bb@webprofil.at>, WEBprofil - Gernot Ploiner e.U.
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

/**
* Generates the json for the mask.json which contains the
* configuration of the created content elements
*
* @author Benjamin Butschell <bb@webprofil.at>
*/
class JsonCodeGenerator extends AbstractCodeGenerator
{
//put your code here
}
41 changes: 17 additions & 24 deletions Classes/CodeGenerator/SqlCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,17 @@
use TYPO3\CMS\Core\Database\Schema\Exception\StatementException;
use TYPO3\CMS\Core\Database\Schema\Exception\UnexpectedSignalReturnValueTypeException;
use TYPO3\CMS\Core\Database\Schema\SchemaMigrator;
use MASK\Mask\Domain\Repository\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use MASK\Mask\Domain\Repository\StorageRepository;
use MASK\Mask\Helper\FieldHelper;

/**
* Generates all the sql needed for mask content elements
*
* @author Benjamin Butschell <bb@webprofil.at>
*/
class SqlCodeGenerator
class SqlCodeGenerator extends AbstractCodeGenerator
{
/**
* StorageRepository
*
* @var StorageRepository
*/
protected $storageRepository;

/**
* @var SchemaMigrator
*/
protected $schemaMigrator;

public function __construct(StorageRepository $storageRepository, SchemaMigrator $schemaMigrator)
{
$this->storageRepository = $storageRepository;
$this->schemaMigrator = $schemaMigrator;
}

/**
* Performs updates, adjusted function from extension_builder
Expand All @@ -74,11 +58,15 @@ public function __construct(StorageRepository $storageRepository, SchemaMigrator
*/
protected function performDbUpdates(array $sqlStatements): array
{
$sqlUpdateSuggestions = $this->schemaMigrator->getUpdateSuggestions($sqlStatements);
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$schemaMigrator = GeneralUtility::makeInstance(SchemaMigrator::class);

$sqlUpdateSuggestions = $schemaMigrator->getUpdateSuggestions($sqlStatements);
$hasErrors = false;

foreach ($sqlUpdateSuggestions as $connectionName => $updateConnection) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionByName($connectionName);
$connection = $connectionPool->getConnectionByName($connectionName);
foreach ($updateConnection as $updateStatements) {
foreach ($updateStatements as $statement) {
try {
Expand Down Expand Up @@ -119,7 +107,8 @@ protected function performDbUpdates(array $sqlStatements): array
*/
public function updateDatabase(): array
{
$json = $this->storageRepository->load();
$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
$json = $storageRepository->load();
$sqlStatements = $this->getSqlByConfiguration($json);
if (count($sqlStatements) > 0) {
return $this->performDbUpdates($sqlStatements);
Expand All @@ -137,6 +126,7 @@ public function getSqlByConfiguration($json): array
$sql_content = [];
$types = array_keys($json);
$nonIrreTables = ['pages', 'tt_content'];
$fieldHelper = GeneralUtility::makeInstance(FieldHelper::class);

// Generate SQL-Statements
if ($types) {
Expand All @@ -157,6 +147,8 @@ public function getSqlByConfiguration($json): array
hidden SMALLINT unsigned DEFAULT '0' NOT NULL,
starttime int(11) unsigned DEFAULT '0' NOT NULL,
endtime int(11) unsigned DEFAULT '0' NOT NULL,
editlock SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
fe_group VARCHAR(255) DEFAULT '0' NOT NULL,
t3ver_oid int(11) DEFAULT '0' NOT NULL,
t3ver_id int(11) DEFAULT '0' NOT NULL,
Expand Down Expand Up @@ -194,7 +186,7 @@ public function getSqlByConfiguration($json): array
foreach ($fields as $fieldKey => $definition) {
$sql_content[] = 'CREATE TABLE ' . $table . " (\n\t" . $fieldKey . ' ' . $definition . "\n);\n";
// if this field is a content field, also add parent columns
$fieldType = $this->storageRepository->getFormType($fieldKey, '', $table);
$fieldType = $fieldHelper->getFormType($fieldKey, '', $table);
if ($fieldType === 'Content') {
$sql_content[] = "CREATE TABLE tt_content (\n\t" . $fieldKey . '_parent' . ' ' . $definition . ",\n\t" . 'KEY ' . $fieldKey . ' (' . $fieldKey . '_parent,pid,deleted)' . "\n);\n";
}
Expand All @@ -218,7 +210,8 @@ public function getSqlByConfiguration($json): array
*/
public function addDatabaseTablesDefinition(AlterTableDefinitionStatementsEvent $event): void
{
$json = $this->storageRepository->load();
$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
$json = $storageRepository->load();
$sql = $this->getSqlByConfiguration($json);
$event->setSqlData(array_merge($event->getSqlData(), $sql));
}
Expand Down
28 changes: 13 additions & 15 deletions Classes/CodeGenerator/TcaCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,29 @@
use MASK\Mask\Utility\GeneralUtility as MaskUtility;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use MASK\Mask\Helper\FieldHelper;

/**
* Generates all the tca needed for mask content elements
*
* @author Benjamin Butschell <bb@webprofil.at>
*/
class TcaCodeGenerator
class TcaCodeGenerator extends AbstractCodeGenerator
{
/**
* @var FieldHelper
*/
protected $fieldHelper;

/**
* StorageRepository
*
* @var StorageRepository
*/
protected $storageRepository;

public function __construct(StorageRepository $storageRepository, FieldHelper $fieldHelper)
public function __construct(StorageRepository $storageRepository = null, FieldHelper $fieldHelper = null)
{
$this->storageRepository = $storageRepository;
$this->fieldHelper = $fieldHelper;
parent::__construct($storageRepository);
if ($fieldHelper) {
$this->fieldHelper = $fieldHelper;
} else {
$this->fieldHelper = GeneralUtility::makeInstance(FieldHelper::class);
}
}

/**
Expand Down Expand Up @@ -157,7 +155,7 @@ public function setElementsTca(): void

// Add all the fields that should be shown
foreach ($elementvalue['columns'] ?? [] as $index => $fieldKey) {
$formType = $this->storageRepository->getFormType($fieldKey, $elementvalue['key'], 'tt_content');
$formType = $this->fieldHelper->getFormType($fieldKey, $elementvalue['key'], 'tt_content');
// Check if this field is of type tab
if ($formType === 'Tab') {
$label = $this->fieldHelper->getLabel($elementvalue['key'], $fieldKey, 'tt_content');
Expand Down Expand Up @@ -193,7 +191,7 @@ public function getPageTca(string $key)
$fieldKey = $columns[$i];

// check if this field is of type tab
$formType = $this->storageRepository->getFormType($fieldKey, $key, 'pages');
$formType = $this->fieldHelper->getFormType($fieldKey, $key, 'pages');
if ($formType === 'Tab') {
$label = $this->fieldHelper->getLabel($key, $fieldKey, 'pages');
// if a tab is in the first position then change the name of the general tab
Expand Down Expand Up @@ -353,7 +351,7 @@ public function processTableTca($table, $tca): array
$i = 0;
foreach ($tca as $fieldKey => $configuration) {
// check if this field is of type tab
$formType = $this->storageRepository->getFormType($fieldKey, '', $table);
$formType = $this->fieldHelper->getFormType($fieldKey, '', $table);
if ($formType === 'Tab') {
$label = $configuration['label'];
// if a tab is in the first position then change the name of the general tab
Expand Down Expand Up @@ -403,7 +401,7 @@ public function addSearchFields($table): void
$searchFields = [];

foreach ($tca as $tcakey => $tcavalue) {
$formType = $this->storageRepository->getFormType($tcakey, '', $table);
$formType = $this->fieldHelper->getFormType($tcakey, '', $table);
if (in_array($formType, ['String', 'Text'])) {
$searchFields[] = $tcakey;
}
Expand Down
Loading

0 comments on commit 7c75e7f

Please sign in to comment.