‪TYPO3CMS  ‪main
InlineMnSymmetric.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
26 
33 {
37  protected ‪$tableName = 'tx_styleguide_inline_mnsymmetric';
38 
44  public function ‪handle(string ‪$tableName): void
45  {
46  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
47 
48  $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
49  $pidOfMainTable = $recordFinder->findPidOfMainTableRecord(‪$tableName);
50  $recordData = GeneralUtility::makeInstance(RecordData::class);
51  $context = GeneralUtility::makeInstance(Context::class);
52 
53  $isFirst = true;
54  $numberOfRelationsForFirstRecord = 2;
55  $relationUids = [];
56  $uidOfFirstRecord = null;
57  for ($i = 0; $i < 4; $i++) {
58  $fieldValues = [
59  'pid' => $pidOfMainTable,
60  'tstamp' => $context->getAspect('date')->get('timestamp'),
61  'crdate' => $context->getAspect('date')->get('timestamp'),
62  ];
63  $connection = $connectionPool->getConnectionForTable(‪$tableName);
64  $connection->insert(‪$tableName, $fieldValues);
65  $fieldValues['uid'] = $connection->lastInsertId();
66  if ($isFirst) {
67  $fieldValues['branches'] = $numberOfRelationsForFirstRecord;
68  $uidOfFirstRecord = $fieldValues['uid'];
69  }
70  $fieldValues = $recordData->generate(‪$tableName, $fieldValues);
71  // Do not update primary identifier uid anymore, db's choke on that for good reason
72  $updateValues = $fieldValues;
73  unset($updateValues['uid']);
74  $connection->update(
76  $updateValues,
77  [ 'uid' => $fieldValues['uid'] ]
78  );
79 
80  $this->‪generateTranslatedRecords($tableName, $fieldValues);
81 
82  if (!$isFirst && count($relationUids) < $numberOfRelationsForFirstRecord) {
83  $relationUids[] = $fieldValues['uid'];
84  }
85 
86  $isFirst = false;
87  }
88 
89  foreach ($relationUids as ‪$uid) {
90  $mmFieldValues = [
91  'pid' => $pidOfMainTable,
92  'tstamp' => $context->getAspect('date')->get('timestamp'),
93  'crdate' => $context->getAspect('date')->get('timestamp'),
94  'hotelid' => $uidOfFirstRecord,
95  'branchid' => ‪$uid,
96  ];
97  $connection = $connectionPool->getConnectionForTable('tx_styleguide_inline_mnsymmetric_mm');
98  $connection->insert(
99  'tx_styleguide_inline_mnsymmetric_mm',
100  $mmFieldValues
101  );
102  }
103  }
104 }
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\InlineMnSymmetric\handle
‪handle(string $tableName)
Definition: InlineMnSymmetric.php:43
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandlerInterface
Definition: TableHandlerInterface.php:26
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler
Definition: AbstractTableHandler.php:32
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler
Definition: AbstractTableHandler.php:18
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\InlineMnSymmetric\$tableName
‪string $tableName
Definition: InlineMnSymmetric.php:36
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\InlineMnSymmetric
Definition: InlineMnSymmetric.php:33
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\AbstractTableHandler\generateTranslatedRecords
‪generateTranslatedRecords(string $tableName, $fieldValues)
Definition: AbstractTableHandler.php:52
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder
Definition: RecordFinder.php:38
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordData
Definition: RecordData.php:28