-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add new site fields to relevant tables, add upgradewizards …
…and tca
- Loading branch information
1 parent
420e669
commit d65586e
Showing
13 changed files
with
264 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\Lux\Update\AddSites; | ||
|
||
use In2code\Lux\Domain\Service\SiteService; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
abstract class AbstractSiteUpgrade | ||
{ | ||
/** | ||
* [ | ||
* 123 => 'site 1', | ||
* 124 => 'site 2', | ||
* ] | ||
* | ||
* @var array | ||
*/ | ||
protected array $mapping = []; | ||
protected SiteService $siteService; | ||
|
||
public function __construct() | ||
{ | ||
$this->siteService = GeneralUtility::makeInstance(SiteService::class); | ||
} | ||
|
||
protected function getSiteIdentifierFromPage(int $pageIdentifier): string | ||
{ | ||
if (array_key_exists($pageIdentifier, $this->mapping)) { | ||
return $this->mapping[$pageIdentifier]; | ||
} | ||
$site = $this->siteService->getSiteFromPageIdentifier($pageIdentifier); | ||
$siteIdentifier = $site->getIdentifier(); | ||
$this->mapping[$pageIdentifier] = $siteIdentifier; | ||
return $siteIdentifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\Lux\Update\AddSites; | ||
|
||
use In2code\Lux\Domain\Model\Download; | ||
use In2code\Lux\Utility\DatabaseUtility; | ||
|
||
class AddSitesForDownloads extends AbstractSiteUpgrade | ||
{ | ||
public function run(): void | ||
{ | ||
$connection = DatabaseUtility::getConnectionForTable(Download::TABLE_NAME); | ||
$records = $connection | ||
->executeQuery('select * from ' . Download::TABLE_NAME . ' where deleted=0') | ||
->fetchAllAssociative(); | ||
foreach ($records as $record) { | ||
$siteIdentifier = $this->getSiteIdentifierFromPage($record['page']); | ||
$connection->executeQuery( | ||
'update ' . Download::TABLE_NAME . ' set site = "' . $siteIdentifier . '" where uid=' . $record['uid'] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\Lux\Update\AddSites; | ||
|
||
use In2code\Lux\Domain\Model\Linkclick; | ||
use In2code\Lux\Utility\DatabaseUtility; | ||
|
||
class AddSitesForLinkclick extends AbstractSiteUpgrade | ||
{ | ||
public function run(): void | ||
{ | ||
$connection = DatabaseUtility::getConnectionForTable(Linkclick::TABLE_NAME); | ||
$records = $connection | ||
->executeQuery('select * from ' . Linkclick::TABLE_NAME . ' where deleted=0') | ||
->fetchAllAssociative(); | ||
foreach ($records as $record) { | ||
$siteIdentifier = $this->getSiteIdentifierFromPage($record['page']); | ||
$connection->executeQuery( | ||
'update ' . Linkclick::TABLE_NAME . ' set site = "' . $siteIdentifier . '" where uid=' . $record['uid'] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\Lux\Update\AddSites; | ||
|
||
use In2code\Lux\Domain\Model\Pagevisit; | ||
use In2code\Lux\Utility\DatabaseUtility; | ||
|
||
class AddSitesForPagevisits extends AbstractSiteUpgrade | ||
{ | ||
public function run(): void | ||
{ | ||
$connection = DatabaseUtility::getConnectionForTable(Pagevisit::TABLE_NAME); | ||
$records = $connection | ||
->executeQuery('select * from ' . Pagevisit::TABLE_NAME . ' where deleted=0') | ||
->fetchAllAssociative(); | ||
foreach ($records as $record) { | ||
$siteIdentifier = $this->getSiteIdentifierFromPage($record['page']); | ||
$connection->executeQuery( | ||
'update ' . Pagevisit::TABLE_NAME . ' set site = "' . $siteIdentifier . '" where uid=' . $record['uid'] | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace In2code\Lux\Update; | ||
|
||
use In2code\Lux\Domain\Model\Pagevisit; | ||
use In2code\Lux\Update\AddSites\AddSitesForDownloads; | ||
use In2code\Lux\Update\AddSites\AddSitesForLinkclick; | ||
use In2code\Lux\Update\AddSites\AddSitesForPagevisits; | ||
use In2code\Lux\Utility\DatabaseUtility; | ||
use Throwable; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Install\Attribute\UpgradeWizard; | ||
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite; | ||
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface; | ||
|
||
#[UpgradeWizard('addSitesUpgradeWizard')] | ||
class AddSitesUpgradeWizard implements UpgradeWizardInterface | ||
{ | ||
public function getIdentifier(): string | ||
{ | ||
return 'addSitesUpgradeWizard'; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return 'LUX: Add sites to existing pagevisit records for multiclient functionality'; | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'Fill some database fields with information about sites'; | ||
} | ||
|
||
public function executeUpdate(): bool | ||
{ | ||
try { | ||
GeneralUtility::makeInstance(AddSitesForPagevisits::class)->run(); | ||
GeneralUtility::makeInstance(AddSitesForDownloads::class)->run(); | ||
GeneralUtility::makeInstance(AddSitesForLinkclick::class)->run(); | ||
} catch (Throwable $exception) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public function updateNecessary(): bool | ||
{ | ||
return DatabaseUtility::isFieldExistingInTable('site', Pagevisit::TABLE_NAME) | ||
&& DatabaseUtility::isAnyFieldFilledInTable('site', Pagevisit::TABLE_NAME) === false; | ||
} | ||
|
||
public function getPrerequisites(): array | ||
{ | ||
return [ | ||
DatabaseUpdatedPrerequisite::class, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.