Skip to content

Commit

Permalink
More v10 Migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Mar 23, 2020
1 parent a79f718 commit 19c9d77
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 329 deletions.
34 changes: 34 additions & 0 deletions Classes/Annotation/DatabaseKey.php
@@ -0,0 +1,34 @@
<?php

declare(strict_types = 1);

namespace HDNET\Autoloader\Annotation;

/**
* @Annotation
* @Target({"CLASS"})
*/
class DatabaseKey
{
/**
* @var string
*/
public $key;

/**
* @throws \InvalidArgumentException
*/
public function __construct(array $values)
{
if (isset($values['value'])) {
$this->key = $values['value'];
} elseif (isset($values['argumentName'])) {
$this->key = $values['argumentName'];
}
}

public function __toString()
{
return (string)$this->key;
}
}
6 changes: 2 additions & 4 deletions Classes/Annotation/DatabaseTable.php
Expand Up @@ -20,10 +20,8 @@ class DatabaseTable
*/
public function __construct(array $values)
{
if (isset($values['value'])) {
$this->argumentName = $values['value'];
} elseif (isset($values['argumentName'])) {
$this->argumentName = $values['argumentName'];
if (\is_string($values['value'])) {
$this->tableName = $values['value'];
}
}

Expand Down
13 changes: 8 additions & 5 deletions Classes/Annotation/WizardTab.php
Expand Up @@ -13,17 +13,20 @@ class WizardTab
/**
* @var string
*/
public $argumentName;
public $config;

/**
* @throws \InvalidArgumentException
*/
public function __construct(array $values)
{
if (isset($values['value'])) {
$this->argumentName = $values['value'];
} elseif (isset($values['argumentName'])) {
$this->argumentName = $values['argumentName'];
if (\is_string($values['value'])) {
$this->config = $values['value'];
}
}

public function __toString()
{
return (string)$this->config;
}
}
79 changes: 0 additions & 79 deletions Classes/Autoload/TempClassLoader.php

This file was deleted.

7 changes: 4 additions & 3 deletions Classes/Cache/AutoloaderFileBackend.php
Expand Up @@ -62,9 +62,10 @@ public function remove($entryIdentifier)
*/
public function flush(): void
{
var_dump(Environment::getVarPath());

exit();
$files = glob(Environment::getVarPath() . '/autoloader_*');
foreach ($files as $file) {
unlink($file);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Classes/Hooks/ElementBackendPreview.php
Expand Up @@ -13,6 +13,7 @@
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -66,8 +67,10 @@ public function getBackendPreview($row)
}

$cacheIdentifier = 'tt-content-preview-' . $row['uid'] . '-' . $row['tstamp'];

/** @var FrontendInterface $cache */
$cache = GeneralUtility::makeInstance(CacheManager::class)
->getCache('cache_pagesection')
->getCache('pagesection')
;
if ($cache->has($cacheIdentifier)) {
return $cache->get($cacheIdentifier);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Loader.php
Expand Up @@ -248,7 +248,7 @@ protected function buildLoaderInformation($objects, $type)
{
$return = [];
foreach ($objects as $object) {
// @var LoaderInterface $object
// LoaderInterface
$return[\get_class($object)] = $object->prepareLoader($this, $type);
}

Expand Down
13 changes: 7 additions & 6 deletions Classes/Loader/ContentObjects.php
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use HDNET\Autoloader\Annotation\EnableRichText;
use HDNET\Autoloader\Annotation\NoHeader;
use HDNET\Autoloader\Annotation\WizardTab;
use HDNET\Autoloader\Loader;
use HDNET\Autoloader\LoaderInterface;
use HDNET\Autoloader\Service\NameMapperService;
Expand Down Expand Up @@ -39,6 +40,9 @@ public function prepareLoader(Loader $loader, int $type): array
{
$loaderInformation = [];

/** @var AnnotationReader $annotationReader */
$annotationReader = GeneralUtility::makeInstance(AnnotationReader::class);

$modelPath = ExtensionManagementUtility::extPath($loader->getExtensionKey()) . 'Classes/Domain/Model/Content/';
$models = FileUtility::getBaseFilesInDir($modelPath, 'php');
if (!empty($models)) {
Expand All @@ -63,6 +67,8 @@ public function prepareLoader(Loader $loader, int $type): array
$richTextFields = [];
$noHeader = $this->isTaggedWithNoHeader($className);

$reflectionClass = new \ReflectionClass($className);

// create labels in the ext_tables run, to have a valid DatabaseConnection
if (LoaderInterface::EXT_TABLES === $type) {
TranslateUtility::assureLabel('wizard.' . $key, $loader->getExtensionKey(), $key . ' (Title)', null, 'tt_content');
Expand All @@ -77,11 +83,6 @@ public function prepareLoader(Loader $loader, int $type): array
$defaultFields = $this->getDefaultTcaFields($noHeader, null);
$fieldConfiguration = array_diff($fieldConfiguration, $defaultFields);

/** @var AnnotationReader $annotationReader */
$annotationReader = GeneralUtility::makeInstance(AnnotationReader::class);

$reflectionClass = new \ReflectionClass($className);

// RTE manipulation
foreach ($reflectionClass->getProperties() as $property) {
$richTextField = $annotationReader->getPropertyAnnotation($property, EnableRichText::class);
Expand All @@ -108,7 +109,7 @@ public function prepareLoader(Loader $loader, int $type): array
'icon' => IconUtility::getByModelName($className, false),
'iconExt' => IconUtility::getByModelName($className, true),
'noHeader' => $noHeader,
'tabInformation' => ReflectionUtility::getFirstTagValue($className, 'wizardTab'),
'tabInformation' => (string)$annotationReader->getClassAnnotation($reflectionClass, WizardTab::class),
];

SmartObjectRegister::register($entry['modelClass']);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Loader/Plugins.php
Expand Up @@ -57,7 +57,7 @@ public function prepareLoader(Loader $loader, int $type): array
$configuration = $annotationReader->getMethodAnnotation($method, Plugin::class);

if (null !== $configuration) {
$pluginKeys = GeneralUtility::trimExplode(' ', implode(' ', (string)$configuration), true);
$pluginKeys = GeneralUtility::trimExplode(' ', (string)$configuration, true);
$actionName = str_replace('Action', '', $method->getName());

foreach ($pluginKeys as $pluginKey) {
Expand Down
6 changes: 6 additions & 0 deletions Classes/Localization/LanguageHandler.php
Expand Up @@ -41,6 +41,12 @@ public function handle($key, $extensionName, $default, $arguments, $overrideLang
if (empty($GLOBALS['TCA'])) {
return $default;
}

if (TYPO3_MODE === 'BE' && !isset($GLOBALS['LANG'])) {
$GLOBALS['LANG'] = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
$GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
}

$value = LocalizationUtility::translate($key, $extensionName, $arguments);

if (null !== $value) {
Expand Down
10 changes: 6 additions & 4 deletions Classes/Service/SmartObjectInformationService.php
Expand Up @@ -9,6 +9,7 @@

use Doctrine\Common\Annotations\AnnotationReader;
use HDNET\Autoloader\Annotation\DatabaseField;
use HDNET\Autoloader\Annotation\DatabaseKey;
use HDNET\Autoloader\Annotation\EnableRichText;
use HDNET\Autoloader\DataSet;
use HDNET\Autoloader\Mapper;
Expand All @@ -17,7 +18,6 @@
use HDNET\Autoloader\Utility\ExtendedUtility;
use HDNET\Autoloader\Utility\IconUtility;
use HDNET\Autoloader\Utility\ModelUtility;
use HDNET\Autoloader\Utility\ReflectionUtility;
use HDNET\Autoloader\Utility\TranslateUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -344,9 +344,11 @@ protected function generateCompleteSqlQuery($modelClassName, $tableName, array $
$fields[] = 'KEY parent (pid)';

// add custom keys set by @key annotations
$reflectionConfiguration = ReflectionUtility::getTagConfigurationForClass($modelClassName, ['key']);
if (!empty($reflectionConfiguration['key'])) {
$additionalKeys = $reflectionConfiguration['key'];

$annotationReader = GeneralUtility::makeInstance(AnnotationReader::class);
$key = $annotationReader->getClassAnnotation(new \ReflectionClass($modelClassName), DatabaseKey::class);
if (null !== $key) {
$additionalKeys = [(string)$key];
array_walk($additionalKeys, function (&$item): void {
$item = 'KEY ' . $item;
});
Expand Down
4 changes: 1 addition & 3 deletions Classes/Utility/ModelUtility.php
Expand Up @@ -170,7 +170,7 @@ public static function getModel($modelName, $data)
$settings->setIgnoreEnableFields(true);

if (isset($data['sys_language_uid']) && (int)$data['sys_language_uid'] > 0) {
GeneralUtility::_GETset((int)$data['sys_language_uid'], 'L');
$_GET['L'] = (int)$data['sys_language_uid'];

if (isset($data['l18n_parent']) && $data['l18n_parent'] > 0) {
$settings->setLanguageOverlayMode(false);
Expand All @@ -180,8 +180,6 @@ public static function getModel($modelName, $data)
}
$object = $query->execute()->getFirst();

GeneralUtility::_GETset(0, 'L');

return $object;
}
}
Expand Down

0 comments on commit 19c9d77

Please sign in to comment.