|
@@ -2,7 +2,8 @@
|
|
|
|
|
|
|
|
namespace Opentalent\OtStats\Domain\Repository;
|
|
namespace Opentalent\OtStats\Domain\Repository;
|
|
|
|
|
|
|
|
-use Opentalent\OtCore\Page\OtPageRepository;
|
|
|
|
|
|
|
+use Opentalent\OtCore\Website\OtPageRepository;
|
|
|
|
|
+use Opentalent\OtCore\Website\OtWebsiteRepository;
|
|
|
use Opentalent\OtStats\Domain\Model\MatomoWebsite;
|
|
use Opentalent\OtStats\Domain\Model\MatomoWebsite;
|
|
|
use PDO;
|
|
use PDO;
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
@@ -30,12 +31,12 @@ class MatomoWebsiteRepository
|
|
|
*
|
|
*
|
|
|
* @var PDO
|
|
* @var PDO
|
|
|
*/
|
|
*/
|
|
|
- private $matomoCnn;
|
|
|
|
|
|
|
+ private PDO $matomoCnn;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @var \TYPO3\CMS\Core\Database\ConnectionPool
|
|
* @var \TYPO3\CMS\Core\Database\ConnectionPool
|
|
|
*/
|
|
*/
|
|
|
- private $connectionPool;
|
|
|
|
|
|
|
+ private ConnectionPool $connectionPool;
|
|
|
|
|
|
|
|
public function injectConnectionPool(\TYPO3\CMS\Core\Database\ConnectionPool $connectionPool)
|
|
public function injectConnectionPool(\TYPO3\CMS\Core\Database\ConnectionPool $connectionPool)
|
|
|
{
|
|
{
|
|
@@ -60,7 +61,8 @@ class MatomoWebsiteRepository
|
|
|
* @param array $data
|
|
* @param array $data
|
|
|
* @return MatomoWebsite
|
|
* @return MatomoWebsite
|
|
|
*/
|
|
*/
|
|
|
- private function fromArray(array $data) {
|
|
|
|
|
|
|
+ private function fromArray(array $data): MatomoWebsite
|
|
|
|
|
+ {
|
|
|
$matomoSite = new MatomoWebsite();
|
|
$matomoSite = new MatomoWebsite();
|
|
|
$matomoSite->setId($data['idsite']);
|
|
$matomoSite->setId($data['idsite']);
|
|
|
$matomoSite->setName($data['name']);
|
|
$matomoSite->setName($data['name']);
|
|
@@ -77,7 +79,8 @@ class MatomoWebsiteRepository
|
|
|
* @param int $id
|
|
* @param int $id
|
|
|
* @return MatomoWebsite|null
|
|
* @return MatomoWebsite|null
|
|
|
*/
|
|
*/
|
|
|
- public function findById(int $id) {
|
|
|
|
|
|
|
+ public function findById(int $id): ?MatomoWebsite
|
|
|
|
|
+ {
|
|
|
$stmt = $this->matomoCnn->prepare(
|
|
$stmt = $this->matomoCnn->prepare(
|
|
|
"SELECT s.idsite, s.name, s.main_url, s.excluded_ips, s.type, s.creator_login
|
|
"SELECT s.idsite, s.name, s.main_url, s.excluded_ips, s.type, s.creator_login
|
|
|
FROM matomo.matomo_site s
|
|
FROM matomo.matomo_site s
|
|
@@ -98,7 +101,8 @@ class MatomoWebsiteRepository
|
|
|
* @param string $uri
|
|
* @param string $uri
|
|
|
* @return MatomoWebsite|null
|
|
* @return MatomoWebsite|null
|
|
|
*/
|
|
*/
|
|
|
- public function findByUri(string $uri) {
|
|
|
|
|
|
|
+ public function findByUri(string $uri): ?MatomoWebsite
|
|
|
|
|
+ {
|
|
|
$stmt = $this->matomoCnn->prepare(
|
|
$stmt = $this->matomoCnn->prepare(
|
|
|
"SELECT s.idsite, s.name, s.main_url, s.excluded_ips, s.type, s.creator_login
|
|
"SELECT s.idsite, s.name, s.main_url, s.excluded_ips, s.type, s.creator_login
|
|
|
FROM matomo.matomo_site s
|
|
FROM matomo.matomo_site s
|
|
@@ -120,16 +124,17 @@ class MatomoWebsiteRepository
|
|
|
* @param int $rootUid
|
|
* @param int $rootUid
|
|
|
* @return MatomoWebsite|null
|
|
* @return MatomoWebsite|null
|
|
|
*/
|
|
*/
|
|
|
- public function findByRootUid(int $rootUid) {
|
|
|
|
|
- $otPageRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtPageRepository::class);
|
|
|
|
|
|
|
+ public function findByRootUid(int $rootUid): ?MatomoWebsite
|
|
|
|
|
+ {
|
|
|
|
|
+ $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
|
|
|
|
|
|
|
|
// Just to make sure this page is actually the root page
|
|
// Just to make sure this page is actually the root page
|
|
|
- $rootPage = $otPageRepository->getRootPageFor($rootUid);
|
|
|
|
|
|
|
+ $website = $otWebsiteRepository->getWebsiteByPageUid($rootUid);
|
|
|
|
|
|
|
|
- if ($rootPage['tx_opentalent_matomo_id'] == null) {
|
|
|
|
|
|
|
+ if ($website['matomo_site_id'] == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- return $this->findById($rootPage['tx_opentalent_matomo_id']);
|
|
|
|
|
|
|
+ return $this->findById($website['matomo_site_id']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -147,23 +152,21 @@ class MatomoWebsiteRepository
|
|
|
$rootPage = $otPageRepository->getRootPageFor($rootUid);
|
|
$rootPage = $otPageRepository->getRootPageFor($rootUid);
|
|
|
$rootUid = $rootPage['uid'];
|
|
$rootUid = $rootPage['uid'];
|
|
|
|
|
|
|
|
|
|
+ $otWebsiteRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OtWebsiteRepository::class);
|
|
|
|
|
+ $website = $otWebsiteRepository->getWebsiteByUid($rootPage['ot_website_uid']);
|
|
|
|
|
+
|
|
|
// Retrieve current site informations
|
|
// Retrieve current site informations
|
|
|
$isDev = ($_SERVER['TYPO3_CONTEXT'] == 'Development');
|
|
$isDev = ($_SERVER['TYPO3_CONTEXT'] == 'Development');
|
|
|
|
|
|
|
|
- $site = $otPageRepository->getSiteFor($rootUid);
|
|
|
|
|
- $title = $site->getIdentifier();
|
|
|
|
|
|
|
+ $title = $website['subdomain'];
|
|
|
if ($isDev) {
|
|
if ($isDev) {
|
|
|
$title = $title . "_DEV";
|
|
$title = $title . "_DEV";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $uri = $site->getBase();
|
|
|
|
|
- if ($isDev && preg_match(self::RELATIVE_PATH_VALIDATION, $uri)) {
|
|
|
|
|
- $host = $_SERVER['HTTP_HOST'];
|
|
|
|
|
- $uri = $host . $uri;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!preg_match('/https?:\/\/.*/', $uri)) {
|
|
|
|
|
- $uri = 'https://' . $uri;
|
|
|
|
|
|
|
+ if ($isDev) {
|
|
|
|
|
+ $uri = rtrim($_SERVER['HTTP_HOST'], '/') . '/' . $website['subdomain'];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $uri = $otWebsiteRepository->getWebsiteDomain($website['uid']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!preg_match(self::DOMAIN_VALIDATION, $uri)) {
|
|
if (!preg_match(self::DOMAIN_VALIDATION, $uri)) {
|
|
@@ -171,10 +174,10 @@ class MatomoWebsiteRepository
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Make sure the current typo3 website has no existing configured matomo website
|
|
// Make sure the current typo3 website has no existing configured matomo website
|
|
|
- if ($rootPage['tx_opentalent_matomo_id'] != null) {
|
|
|
|
|
|
|
+ if ($website['matomo_site_id'] != null) {
|
|
|
// Check if the registered matomo site still exist. If it does, throw an error.
|
|
// Check if the registered matomo site still exist. If it does, throw an error.
|
|
|
- if ($this->findById($rootPage['tx_opentalent_matomo_id']) != null) {
|
|
|
|
|
- throw new \RuntimeException('This website has already been registered (matomo id: ' . $rootPage['tx_opentalent_matomo_id'] . ')');
|
|
|
|
|
|
|
+ if ($this->findById($website['matomo_site_id']) != null) {
|
|
|
|
|
+ throw new \RuntimeException('This website has already been registered (matomo id: ' . $website['matomo_site_id'] . ')');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -217,11 +220,11 @@ class MatomoWebsiteRepository
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Update typo3 DB
|
|
// Update typo3 DB
|
|
|
- $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
|
|
|
|
+ $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
|
|
|
$queryBuilder
|
|
$queryBuilder
|
|
|
- ->update('pages')
|
|
|
|
|
- ->where($queryBuilder->expr()->eq('uid', $rootUid))
|
|
|
|
|
- ->set('tx_opentalent_matomo_id', $matomoSiteId)
|
|
|
|
|
|
|
+ ->update('ot_websites')
|
|
|
|
|
+ ->where($queryBuilder->expr()->eq('uid', $website['uid']))
|
|
|
|
|
+ ->set('matomo_site_id', $matomoSiteId)
|
|
|
->execute();
|
|
->execute();
|
|
|
|
|
|
|
|
// finalize
|
|
// finalize
|
|
@@ -258,9 +261,9 @@ class MatomoWebsiteRepository
|
|
|
// Update typo3 DB
|
|
// Update typo3 DB
|
|
|
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
$queryBuilder
|
|
$queryBuilder
|
|
|
- ->update('pages')
|
|
|
|
|
- ->where($queryBuilder->expr()->eq('uid', $rootUid))
|
|
|
|
|
- ->set('tx_opentalent_matomo_id', null)
|
|
|
|
|
|
|
+ ->update('ot_websites')
|
|
|
|
|
+ ->where($queryBuilder->expr()->eq('matomo_site_id', $matomoSite->getId()))
|
|
|
|
|
+ ->set('matomo_site_id', null)
|
|
|
->execute();
|
|
->execute();
|
|
|
|
|
|
|
|
// finalize
|
|
// finalize
|