diff --git a/.check-author.yml b/.check-author.yml index d33306f..9d0754c 100644 --- a/.check-author.yml +++ b/.check-author.yml @@ -12,3 +12,6 @@ mapping: - "Andreas Dziemba " - "adziemba " - "Andreas Dziemba " + 'Ingolf Steinhardt ': + - 'zonky2 ' + - 'zonky ' diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml new file mode 100644 index 0000000..d153b7f --- /dev/null +++ b/.github/workflows/diagnostics.yml @@ -0,0 +1,52 @@ +name: MetaModels attribute_translatedtablemulti + +on: + push: + branches-ignore: + - '**-translation' + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + php: [7.4] + contao: [~4.9.0] + + steps: + - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Pull source + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # see https://github.com/shivammathur/setup-php + - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Setup PHP. + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache composer cache directory + uses: actions/cache@v1 + env: + cache-name: composer-cache-dir + with: + path: ~/.cache/composer + key: ${{ runner.os }}-build-${{ env.cache-name }} + + - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache vendor directory + uses: actions/cache@v1 + env: + cache-name: composer-vendor + with: + path: vendor + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + + - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Install composer dependencies + run: composer update --prefer-dist --no-interaction --no-suggest + + - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Run tests + run: ant -keep-going diff --git a/.gitignore b/.gitignore index adfdf7a..92d03d1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .DS_Store Thumbs.db -# IDEs +# IDEs .buildpath .project .settings/ @@ -16,4 +16,5 @@ vendor/ # build build/ -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4f52bb5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,62 +0,0 @@ -dist: xenial - -addons: - apt: - packages: - - ant-optional - -language: php - -php: - - "7.3" - - "7.2" - - "7.1" - -env: - - CONTAO_VERSION=~4.7.0 - - CONTAO_VERSION=~4.6.0 - - CONTAO_VERSION=~4.5.0 - - CONTAO_VERSION=~4.4.0 - -# Exclude impossible Contao Version combinations. -matrix: - exclude: - fast_finish: true - allow_failures: - - env: CONTAO_VERSION=~4.7.0 - - env: CONTAO_VERSION=~4.6.0 - - env: CONTAO_VERSION=~4.5.0 - -before_script: - - echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - travis_retry composer self-update && composer --version - - travis_retry composer require contao/core-bundle $CONTAO_VERSION --no-update - - > - if [ "x${TRAVIS_TAG}" != "x" ]; then - export COMPOSER_ROOT_VERSION=${TRAVIS_TAG} - else - export COMPOSER_ROOT_VERSION=$([[ ${TRAVIS_BRANCH} =~ (hotfix|release)/([0-9.]*(-(alpha|beta|rc)[0-9]+)?) ]] \ - && echo ${BASH_REMATCH[2]} \ - || echo dev-${TRAVIS_BRANCH}) - fi - - echo "Using root version ${COMPOSER_ROOT_VERSION}" - - > - echo "PHP version: ${TRAVIS_PHP_VERSION}"; - if [ "x${TRAVIS_PHP_VERSION}" == "xnightly" ]; then - travis_retry composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-suggest - else - travis_retry composer update --prefer-dist --no-interaction --no-suggest - fi -script: ant -keep-going - -# Hack to make things work again - we can not use a shallow repository. -git: - depth: 2147483647 - -branches: - except: - - /.*-translation/ - -cache: - directories: - - vendor \ No newline at end of file diff --git a/README.md b/README.md index 863e4f4..62b4732 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/MetaModels/attribute_translatedtablemulti.svg)](https://travis-ci.org/MetaModels/attribute_translatedtablemulti/branches) +[![Build Status](https://github.com/MetaModels/attribute_translatedtablemulti/actions/workflows/diagnostics.yml/badge.svg)](https://github.com/MetaModels/attribute_translatedtablemulti/actions) [![Latest Version tagged](http://img.shields.io/github/tag/MetaModels/attribute_translatedtablemulti.svg)](https://github.com/MetaModels/attribute_translatedtablemulti/tags) [![Latest Version on Packagist](http://img.shields.io/packagist/v/MetaModels/attribute_translatedtablemulti.svg)](https://packagist.org/packages/MetaModels/attribute_translatedtablemulti) [![Installations via composer per month](http://img.shields.io/packagist/dm/MetaModels/attribute_translatedtablemulti.svg)](https://packagist.org/packages/MetaModels/attribute_translatedtablemulti) @@ -56,4 +56,4 @@ $GLOBALS['TL_CONFIG']['metamodelsattribute_multi']['mm_test']['multi_test'] = ar ), ), ); -``` \ No newline at end of file +``` diff --git a/build.xml b/build.xml index b34c429..2e571d0 100644 --- a/build.xml +++ b/build.xml @@ -6,4 +6,5 @@ --> - \ No newline at end of file + + diff --git a/composer.json b/composer.json index d905f09..6444604 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "multicolumnwizard" ], "type": "contao-bundle", - "homepage": "http://now.metamodel.me/", + "homepage": "https://now.metamodel.me/", "license": "LGPL-3.0-or-later", "authors": [ { @@ -29,7 +29,7 @@ { "name": "Christian Schiffler", "email": "c.schiffler@cyberspectrum.de", - "homepage": "http://www.cyberspectrum.de", + "homepage": "https://www.cyberspectrum.de", "role": "Developer" }, { @@ -49,18 +49,18 @@ "source": "https://github.com/MetaModels/attribute_translatedtablemulti" }, "require": { - "php": "^7.1", - "contao-community-alliance/dc-general": "^2.1.3", - "contao/core-bundle": "^4.4.8", - "metamodels/core": "^2.1.1", - "symfony/dependency-injection": "^3.3 || ^4.0", - "symfony/http-kernel": "^3.3 || ^4.0", - "ext-pdo": "*" + "php": "^7.4", + "ext-pdo": "*", + "contao-community-alliance/dc-general": "^2.2", + "contao/core-bundle": "^4.9.0, <4.13.0", + "metamodels/core": "^2.2", + "symfony/dependency-injection": "^4.4", + "symfony/http-kernel": "^4.4" }, "require-dev": { "contao/manager-plugin": "^2.1", - "menatwork/contao-multicolumnwizard-bundle": "^3.4", - "phpcq/all-tasks": "^1.2" + "menatwork/contao-multicolumnwizard-bundle": "^3.5", + "phpcq/all-tasks": "^1.3" }, "autoload": { "psr-4": { @@ -78,7 +78,14 @@ "extra": { "contao-manager-plugin": "MetaModels\\AttributeTranslatedTableMultiBundle\\ContaoManager\\Plugin", "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-feature/2.2.0": "2.2.x-dev" } + }, + "config": { + "allow-plugins": { + "contao-components/installer": false, + "contao/manager-plugin": false + }, + "sort-packages": true } } diff --git a/src/Attribute/TranslatedTableMulti.php b/src/Attribute/TranslatedTableMulti.php index fe76e6b..86b027b 100644 --- a/src/Attribute/TranslatedTableMulti.php +++ b/src/Attribute/TranslatedTableMulti.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,7 +18,9 @@ * @author David Greminger * @author David Maack * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @author Sven Baumann + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -38,7 +40,6 @@ */ class TranslatedTableMulti extends Base implements ITranslated, IComplex { - /** * Database connection. * @@ -81,7 +82,7 @@ public function __construct(IMetaModel $objMetaModel, array $arrData = [], Conne */ public function getAttributeSettingNames() { - return array_merge(parent::getAttributeSettingNames(), array()); + return array_merge(parent::getAttributeSettingNames(), []); } /** @@ -99,7 +100,7 @@ protected function getValueTable() * * @SuppressWarnings(PHPMD.Superglobals) */ - public function getFieldDefinition($arrOverrides = array()) + public function getFieldDefinition($arrOverrides = []) { // Get table and column $strTable = $this->getMetaModel()->getTableName(); @@ -107,7 +108,7 @@ public function getFieldDefinition($arrOverrides = array()) $arrFieldDef = parent::getFieldDefinition($arrOverrides); $arrFieldDef['inputType'] = 'multiColumnWizard'; - $arrFieldDef['eval']['columnFields'] = array(); + $arrFieldDef['eval']['columnFields'] = []; // Check for override in local config if (isset($GLOBALS['TL_CONFIG']['metamodelsattribute_multi'][$strTable][$strField])) { @@ -127,47 +128,58 @@ public function getFieldDefinition($arrOverrides = array()) } /** - * Build the where clause + * Build the where clause. + * + * @param QueryBuilder $queryBuilder The query builder. + * + * @param null|array|int $mixIds One, none or many ids to use. + * + * @param null $strLangCode The language code, optional. * - * @param QueryBuilder $queryBuilder - * @param $mixIds - * @param null $strLangCode - * @param null $intRow - * @param null $varCol + * @param null $intRow The row number, optional. + * + * @param null $varCol The col number, optional. + * + * @param null $tableAlias The table alias, optional. */ protected function buildWhere( QueryBuilder $queryBuilder, $mixIds, $strLangCode = null, $intRow = null, - $varCol = null + $varCol = null, + $tableAlias = null ) { + if (null !== $tableAlias) { + $tableAlias .= '.'; + } + $queryBuilder - ->andWhere('att_id = :att_id') + ->andWhere($tableAlias . 'att_id = :att_id') ->setParameter('att_id', (int) $this->get('id')); if (!empty($mixIds)) { if (is_array($mixIds)) { $queryBuilder - ->andWhere('item_id IN (:item_ids)') + ->andWhere($tableAlias . 'item_id IN (:item_ids)') ->setParameter('item_ids', $mixIds, Connection::PARAM_STR_ARRAY); } else { $queryBuilder - ->andWhere('item_id = :item_id') + ->andWhere($tableAlias . 'item_id = :item_id') ->setParameter('item_id', $mixIds); } } if (is_int($intRow) && is_string($varCol)) { $queryBuilder - ->andWhere('row = :row AND col = :col') + ->andWhere($tableAlias . 'row = :row AND ' . $tableAlias . 'col = :col') ->setParameter('row', $intRow) ->setParameter('col', $varCol); } if ($strLangCode) { $queryBuilder - ->andWhere('langcode = :langcode') + ->andWhere($tableAlias . 'langcode = :langcode') ->setParameter('langcode', $strLangCode); } } @@ -178,7 +190,7 @@ protected function buildWhere( public function valueToWidget($varValue) { if (!is_array($varValue)) { - return array(); + return []; } $widgetValue = array(); @@ -245,13 +257,13 @@ public function getTranslatedDataFor($arrIds, $strLangCode) { $queryBuilder = $this->connection->createQueryBuilder() ->select('*') - ->from($this->getValueTable()) - ->orderBy('row', 'ASC') - ->addOrderBy('col', 'ASC'); + ->from($this->getValueTable(), 't') + ->orderBy('t.row', 'ASC') + ->addOrderBy('t.col', 'ASC'); - $this->buildWhere($queryBuilder, $arrIds, $strLangCode); + $this->buildWhere($queryBuilder, $arrIds, $strLangCode, null, null, 't'); $statement = $queryBuilder->execute(); - $arrReturn = array(); + $arrReturn = []; while ($value = $statement->fetch(\PDO::FETCH_ASSOC)) { $arrReturn[$value['item_id']][$value['row']][$value['col']] = $value; } @@ -264,9 +276,9 @@ public function getTranslatedDataFor($arrIds, $strLangCode) * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function searchForInLanguages($strPattern, $arrLanguages = array()) + public function searchForInLanguages($strPattern, $arrLanguages = []) { - return array(); + return []; } @@ -283,7 +295,7 @@ public function setTranslatedDataFor($arrValues, $strLangCode) foreach ($arrIds as $intId) { // Walk every row. - foreach ($arrValues[$intId] as $row) { + foreach ((array) $arrValues[$intId] as $row) { // Walk every column and update / insert the value. foreach ($row as $col) { $values = $this->getSetValues($col, $intId, $strLangCode); @@ -294,7 +306,7 @@ public function setTranslatedDataFor($arrValues, $strLangCode) $queryBuilder = $this->connection->createQueryBuilder()->insert($this->getValueTable()); foreach ($values as $name => $value) { $queryBuilder - ->setValue($name, ':' . $name) + ->setValue($this->getValueTable() . '.' . $name, ':' . $name) ->setParameter($name, $value); } @@ -304,7 +316,7 @@ public function setTranslatedDataFor($arrValues, $strLangCode) $queryBuilder = $this->connection->createQueryBuilder()->update($this->getValueTable()); foreach ($values as $name => $value) { $queryBuilder - ->set($name, ':' . $name) + ->set($this->getValueTable() . '.' . $name, ':' . $name) ->setParameter($name, $value); } @@ -323,7 +335,7 @@ public function setTranslatedDataFor($arrValues, $strLangCode) public function unsetValueFor($arrIds, $strLangCode) { $queryBuilder = $this->connection->createQueryBuilder()->delete($this->getValueTable()); - $this->buildWhere($queryBuilder, $arrIds, $strLangCode); + $this->buildWhere($queryBuilder, $arrIds, $strLangCode, null, null, $this->getValueTable()); $queryBuilder->execute(); } @@ -334,7 +346,7 @@ public function unsetValueFor($arrIds, $strLangCode) */ public function getFilterOptions($idList, $usedOnly, &$arrCount = null) { - return array(); + return []; } /** @@ -361,7 +373,7 @@ public function getDataFor($arrIds) // Second round, fetch fallback languages if not all items could be resolved. if ((count($arrReturn) < count($arrIds)) && ($strActiveLanguage != $strFallbackLanguage)) { - $arrFallbackIds = array(); + $arrFallbackIds = []; foreach ($arrIds as $intId) { if (empty($arrReturn[$intId])) { $arrFallbackIds[] = $intId; diff --git a/src/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtension.php b/src/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtension.php index ab28048..8fc2fa9 100644 --- a/src/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtension.php +++ b/src/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtension.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTranslatedTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -29,6 +30,8 @@ /** * Class MetaModelsAttributeTranslatedTableMultiExtension * + * @SuppressWarnings(PHPMD.LongClassName) + * * @package MetaModels\AttributeTranslatedTableMultiBundle\DependencyInjection */ class MetaModelsAttributeTranslatedTableMultiExtension extends Extension diff --git a/src/MetaModelsAttributeTranslatedTableMultiBundle.php b/src/MetaModelsAttributeTranslatedTableMultiBundle.php index 3d61e67..fb60490 100644 --- a/src/MetaModelsAttributeTranslatedTableMultiBundle.php +++ b/src/MetaModelsAttributeTranslatedTableMultiBundle.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTranslatedTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -25,6 +26,8 @@ /** * This is the bundle class. + * + * @SuppressWarnings(PHPMD.LongClassName) */ class MetaModelsAttributeTranslatedTableMultiBundle extends Bundle { diff --git a/src/Migration/ChangeTranslatedTableNameMigration.php b/src/Migration/ChangeTranslatedTableNameMigration.php new file mode 100644 index 0000000..06b9ebb --- /dev/null +++ b/src/Migration/ChangeTranslatedTableNameMigration.php @@ -0,0 +1,123 @@ + + * @author Ingolf Steinhardt + * @author Sven Baumann + * @copyright 2012-2022 The MetaModels team. + * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later + * @filesource + */ + +declare(strict_types=1); + +namespace MetaModels\AttributeTranslatedTableMultiBundle\Migration; + +use Contao\CoreBundle\Migration\AbstractMigration; +use Contao\CoreBundle\Migration\MigrationResult; +use Doctrine\DBAL\Connection; +use RuntimeException; + +/** + * Change the database table name from "tl_metamodel_translatedmulti" to "tl_metamodel_translatedtablemulti". + */ +class ChangeTranslatedTableNameMigration extends AbstractMigration +{ + /** + * The database connection. + * + * @var Connection + */ + private $connection; + + /** + * Create a new instance. + * + * @param Connection $connection The database connection. + */ + public function __construct(Connection $connection) + { + $this->connection = $connection; + } + + /** + * Return the name. + * + * @return string + */ + public function getName(): string + { + return 'Change table name in MetaModels attribute translatedtablemulti.'; + } + + /** + * Must only run if: + * - the MM tables tl_metamodel_translatedmulti exist. + * + * @return bool + * + * @throws RuntimeException If the old table not migrated. + */ + public function shouldRun(): bool + { + $schemaManager = $this->connection->getSchemaManager(); + if ($schemaManager->tablesExist(['tl_metamodel_translatedmulti']) + && $schemaManager->tablesExist(['tl_metamodel_translatedtablemulti'])) { + $error = 'Could not migrate attribute_translatedtablemulti.'; + $error .= ' Reason: There are both tables available.'; + $error .= ' Old table: tl_metamodel_translatedmulti | New table: attribute_translatedtablemulti.'; + $error .= ' Please migrate the tables manually or delete one table.'; + throw new RuntimeException($error); + } + + if ($schemaManager->tablesExist(['tl_metamodel_translatedmulti'])) { + return true; + } + + return false; + } + + /** + * Change table name tl_metamodel_translatedmulti. + * + * @return MigrationResult + */ + public function run(): MigrationResult + { + $schemaManager = $this->connection->getSchemaManager(); + + if ($schemaManager->tablesExist(['tl_metamodel_translatedmulti'])) { + $schemaManager->renameTable('tl_metamodel_translatedmulti', 'tl_metamodel_translatedtablemulti'); + + $this->connection->createQueryBuilder() + ->update('tl_metamodel_attribute', 't') + ->set('t.type', ':new_name') + ->where('t.type=:old_name') + ->setParameter('new_name', 'translatedtablemulti') + ->setParameter('old_name', 'translatedmulti') + ->execute(); + + $this->connection->createQueryBuilder() + ->update('tl_metamodel_rendersetting', 't') + ->set('t.template', ':new_name') + ->where('t.template=:old_name') + ->setParameter('new_name', 'mm_attr_translatedtablemulti') + ->setParameter('old_name', 'mm_attr_translatedmulti') + ->execute(); + + return new MigrationResult(true, 'Rename table tl_metamodel_multi to tl_metamodel_translatedtablemulti.'); + } + + return new MigrationResult(false, ''); + } +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 978dfb8..303e6f9 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -4,4 +4,10 @@ services: arguments: - "@database_connection" tags: - - { name: metamodels.attribute_factory } \ No newline at end of file + - { name: metamodels.attribute_factory } + + MetaModels\AttributeTranslatedTableMultiBundle\Migration\ChangeTranslatedTableNameMigration: + arguments: + - '@database_connection' + tags: + - name: contao.migration diff --git a/src/Resources/contao/languages/en/tl_metamodel_attribute.php b/src/Resources/contao/languages/en/tl_metamodel_attribute.php index df54693..917220e 100644 --- a/src/Resources/contao/languages/en/tl_metamodel_attribute.php +++ b/src/Resources/contao/languages/en/tl_metamodel_attribute.php @@ -1,21 +1,25 @@ * @author Stefan Heimes - * @author Andreas Dziemba - * @copyright 2018 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later + * @filesource */ /** * Fields */ -$GLOBALS['TL_LANG']['tl_metamodel_attribute']['typeOptions']['translatedtablemulti'] = 'Translated multi table'; +$GLOBALS['TL_LANG']['tl_metamodel_attribute']['typeOptions']['translatedtablemulti'] = 'Translated table multi (MCW)'; diff --git a/src/Resources/contao/config/runonce.php b/src/Resources/contao/languages/en/tl_metamodel_rendersetting.php similarity index 61% rename from src/Resources/contao/config/runonce.php rename to src/Resources/contao/languages/en/tl_metamodel_rendersetting.php index f015bf2..6c98467 100644 --- a/src/Resources/contao/config/runonce.php +++ b/src/Resources/contao/languages/en/tl_metamodel_rendersetting.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,12 +12,11 @@ * * @package MetaModels * @subpackage AttributeTranslatedTableMulti - * @author Andreas Dziemba - * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ -$objRunonce = new \MetaModels\AttributeTranslatedTableMultiBundle\Runonce\TranslatedTableMultiRunOnce(); -$objRunonce->run(); +$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['translatedtablemulti_hide_tablehead'] = + ['Hide tablehead', 'Select to hide the head of the table.']; diff --git a/src/Resources/contao/templates/mm_attr_translatedtablemulti.html5 b/src/Resources/contao/templates/mm_attr_translatedtablemulti.html5 index ce07159..771c54a 100644 --- a/src/Resources/contao/templates/mm_attr_translatedtablemulti.html5 +++ b/src/Resources/contao/templates/mm_attr_translatedtablemulti.html5 @@ -1,28 +1,31 @@ attribute->getMetaModel()->getFallbackLanguage(); -$strActiveLang = $this->attribute->getMetaModel()->getActiveLanguage(); -$strActiveLang = array_key_exists($strActiveLang, $this->attribute->getMetaModel()->get('languages')) ? - $strActiveLang : - $strFallbackLang; -?> +\Contao\Controller::loadDataContainer($this->attribute->getMetaModel()->getTableName()); +\Contao\Controller::loadLanguageFile($this->attribute->getMetaModel()->getTableName()); - -attribute->get('translatedtablemulti_cols')[$strFallbackLang]); if (!$this->settings->get('translatedtablemulti_hide_tablehead')) : ?> - +$config = $GLOBALS['TL_CONFIG']['metamodelsattribute_multi'][$this->attribute->getMetaModel()->getTableName( + )][$this->attribute->getColName()] ?? []; +if (!isset($config['columnFields']) || !is_array($config['columnFields'])) { + $config['columnFields'] = []; +} +$columnNames = array_keys($config['columnFields']); +?> +
+ settings->get('translatedtablemulti_hide_tablehead')) : ?> + - attribute->get('translatedtablemulti_cols')[$strActiveLang]) ? $this->attribute->get('translatedtablemulti_cols')[$strActiveLang]: array() as $headCol) : ?> - + + - - + + - raw as $k => $row) : ?> - - $col): ?> - - - - + raw as $k => $row) : ?> + + + + + +
diff --git a/src/Resources/contao/templates/mm_attr_translatedtablemulti.text b/src/Resources/contao/templates/mm_attr_translatedtablemulti.text index cb75e2c..1a7c81e 100644 --- a/src/Resources/contao/templates/mm_attr_translatedtablemulti.text +++ b/src/Resources/contao/templates/mm_attr_translatedtablemulti.text @@ -1,10 +1,18 @@ -raw as $k => $row) -{ - foreach ($row as $kk => $col) - { - echo (($kk !=0) ? ' ': '' ).$col['value']; - } - if ($k != (count($this->raw['value']) -1)) echo "\n"; +attribute->getMetaModel()->getTableName()); +\Contao\Controller::loadLanguageFile($this->attribute->getMetaModel()->getTableName()); + +$config = $GLOBALS['TL_CONFIG']['metamodelsattribute_multi'][$this->attribute->getMetaModel()->getTableName( + )][$this->attribute->getColName()] ?? []; +if (!isset($config['columnFields']) || !is_array($config['columnFields'])) { + $config['columnFields'] = []; +} +$columnNames = array_keys($config['columnFields']); + +$rowCount = count((array) $this->raw); +foreach ((array) $this->raw as $k => $row) { + foreach ($columnNames as $kk => $columnName) { + echo $row[$columnName]['value'] ?? ''; + } + if ($k != ($rowCount -1)) echo "\n"; } -?> \ No newline at end of file diff --git a/src/Runonce/TranslatedTableMultiRunOnce.php b/src/Runonce/TranslatedTableMultiRunOnce.php deleted file mode 100644 index 8cd9e87..0000000 --- a/src/Runonce/TranslatedTableMultiRunOnce.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. - * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later - * @filesource - */ - -namespace MetaModels\AttributeTranslatedTableMultiBundle\Runonce; - -use Contao\Controller; - -/** - * Class TranslatedTableMultiRunOnce - * - * @package MetaModels\AttributeTranslatedTableMultiBundle - */ -class TranslatedTableMultiRunOnce extends Controller -{ - /** - * Initialize the object - */ - public function __construct() - { - parent::__construct(); - $this->import('Database'); - } - - /** - * Run the controller - * Update from attribute_translatedmulto to attribute_translatedtablemulti - * - * @return void|null - */ - public function run() - { - if ($this->Database->tableExists('tl_metamodel_translatedtablemulti')) { - return; - } - - if ($this->Database->tableExists('tl_metamodel_translatedmulti')) { - $this->Database - ->prepare('RENAME TABLE tl_metamodel_translatedmulti TO tl_metamodel_translatedtablemulti') - ->execute(); - - $this->Database - ->prepare("UPDATE tl_metamodel_attribute SET type='translatedtablemulti' WHERE type='translatedmulti'") - ->execute(); - } - - $this->Database - ->prepare("UPDATE tl_metamodel_attribute SET type='translatedtablemulti' WHERE type='translatedmulti'") - ->execute(); - - $sql = "UPDATE tl_metamodel_rendersetting -SET template='mm_attr_translatedtablemulti' -WHERE template='mm_attr_translatedmulti'"; - - $this->Database - ->prepare($sql) - ->execute(); - } -} diff --git a/tests/Test/Attribute/TranslatedTableMultiAttributeTypeFactoryTest.php b/tests/Test/Attribute/TranslatedTableMultiAttributeTypeFactoryTest.php index 0c37e94..eb655e4 100644 --- a/tests/Test/Attribute/TranslatedTableMultiAttributeTypeFactoryTest.php +++ b/tests/Test/Attribute/TranslatedTableMultiAttributeTypeFactoryTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -30,6 +31,8 @@ /** * Test the attribute factory. + * + * @covers \MetaModels\AttributeTranslatedTableMultiBundle\Attribute\AttributeTypeFactory */ class TranslatedTableMultiAttributeTypeFactoryTest extends TestCase { diff --git a/tests/Test/Attribute/TranslatedTableMultiTest.php b/tests/Test/Attribute/TranslatedTableMultiTest.php index 9c25a58..2e87ff7 100644 --- a/tests/Test/Attribute/TranslatedTableMultiTest.php +++ b/tests/Test/Attribute/TranslatedTableMultiTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -28,6 +29,8 @@ /** * Unit tests to test class Multi. + * + * @covers \MetaModels\AttributeTranslatedTableMultiBundle\Attribute\TranslatedTableMulti */ class TranslatedTableMultiTest extends TestCase { diff --git a/tests/Test/ContaoManager/PluginTest.php b/tests/Test/ContaoManager/PluginTest.php index f1f4fdc..0406a2b 100644 --- a/tests/Test/ContaoManager/PluginTest.php +++ b/tests/Test/ContaoManager/PluginTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -31,6 +32,8 @@ /** * Unit tests the contao manager plugin. + * + * @covers \MetaModels\AttributeTranslatedTableMultiBundle\ContaoManager\Plugin */ class PluginTest extends TestCase { @@ -58,13 +61,13 @@ public function testBundleConfig() $plugin = new Plugin(); $bundles = $plugin->getBundles($parser); - $this->assertContainsOnlyInstancesOf(BundleConfig::class, $bundles); - $this->assertCount(1, $bundles); + self::assertContainsOnlyInstancesOf(BundleConfig::class, $bundles); + self::assertCount(1, $bundles); /** @var BundleConfig $bundleConfig */ $bundleConfig = $bundles[0]; - $this->assertEquals($bundleConfig->getLoadAfter(), [ContaoCoreBundle::class, MetaModelsCoreBundle::class]); - $this->assertEquals($bundleConfig->getReplace(), ['metamodelsattribute_translatedtablemulti', 'metamodelsattribute_translatedmulti']); + self::assertEquals([ContaoCoreBundle::class, MetaModelsCoreBundle::class], $bundleConfig->getLoadAfter()); + self::assertEquals(['metamodelsattribute_translatedmulti', 'metamodelsattribute_translatedtablemulti'], $bundleConfig->getReplace()); } } diff --git a/tests/Test/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtensionTest.php b/tests/Test/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtensionTest.php index df8607e..f2760b3 100644 --- a/tests/Test/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtensionTest.php +++ b/tests/Test/DependencyInjection/MetaModelsAttributeTranslatedTableMultiExtensionTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Ingolf Steinhardt + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -30,6 +31,8 @@ /** * This test case test the extension. + * + * @covers \MetaModels\AttributeTranslatedTableMultiBundle\DependencyInjection\MetaModelsAttributeRatingExtension */ class MetaModelsAttributeTranslatedTableMultiExtensionTest extends TestCase { diff --git a/tests/Test/DeprecatedAutoloaderTest.php b/tests/Test/DeprecatedAutoloaderTest.php index 69763d6..72b9381 100644 --- a/tests/Test/DeprecatedAutoloaderTest.php +++ b/tests/Test/DeprecatedAutoloaderTest.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/attribute_translatedtablemulti. * - * (c) 2012-2019 The MetaModels team. + * (c) 2012-2022 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,8 @@ * @subpackage AttributeTableMulti * @author Andreas Dziemba * @author Stefan Heimes - * @copyright 2012-2019 The MetaModels team. + * @author Sven Baumann + * @copyright 2012-2022 The MetaModels team. * @license https://github.com/MetaModels/attribute_translatedtablemulti/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -29,6 +30,8 @@ * This class tests if the deprecated autoloader works. * * @package MetaModels\AttributeTranslatedTableMultiBundle\Test + * + * @covers \MetaModels\AttributeTranslatedTableMultiBundle\DeprecatedAutoloader */ class DeprecatedAutoloaderTest extends TestCase { diff --git a/travis.php.ini b/travis.php.ini deleted file mode 100644 index 2a30f41..0000000 --- a/travis.php.ini +++ /dev/null @@ -1 +0,0 @@ -memory_limit = 2G