From 9ddb60f870835de7379436cd0e7b07dcce5877cb Mon Sep 17 00:00:00 2001 From: Alexander Bigga Date: Mon, 22 Apr 2024 22:27:12 +0200 Subject: [PATCH] [BUGFIX] Include geoPHP as Phar into TER package --- .gitignore | 2 +- Classes/TceMain.php | 25 ++++++++++++++++++++++++- composer.json | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3132a05..1ff76ea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ package-lock.json /var /config - +Resources/Private/geophp.phar diff --git a/Classes/TceMain.php b/Classes/TceMain.php index 129b61c..6253647 100644 --- a/Classes/TceMain.php +++ b/Classes/TceMain.php @@ -7,6 +7,7 @@ use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Resource\FileRepository; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; class TceMain @@ -61,6 +62,14 @@ public function processDatamap_afterDatabaseOperations( return; } + /* + * If ods_osm is installed via composer, the class geoPHP is already known. + * Otherwise we use the copy in the local folder which is only available in the TER package. + */ + if (!class_exists(geoPHP::class)) { + require_once 'phar://' . ExtensionManagementUtility::extPath('ods_osm', 'Resources/Private/geophp.phar/vendor/autoload.php'); + } + switch ($table) { case 'tx_odsosm_track': if (is_int($id)) { @@ -223,7 +232,21 @@ public function processDatamap_postProcessFieldArray($status, $table, $id, &$fie $this->lon = []; $this->lat = []; - $polygon = geoPHP::load(($fieldArray['data'])); + /* + * If ods_osm is installed via composer, the class geoPHP is already known. + * Otherwise we use the copy in the local folder which is only available in the TER package. + */ + if (!class_exists(geoPHP::class)) { + require_once 'phar://' . ExtensionManagementUtility::extPath('ods_osm', 'Resources/Private/geophp.phar/vendor/autoload.php'); + } + + try { + $polygon = geoPHP::load(($fieldArray['data'])); + } catch (\Exception $e) { + // silently ignore failure of parsing geojson + break; + } + if ($polygon) { $box = $polygon->getBBox(); diff --git a/composer.json b/composer.json index 9b577cb..e0b7d3e 100644 --- a/composer.json +++ b/composer.json @@ -65,5 +65,13 @@ "extension-key": "ods_osm", "web-dir": ".Build/public" } + }, + "scripts": { + "build:ter-package": [ + "@composer global require clue/phar-composer", + "(mkdir -p /tmp/vendors && cd /tmp/vendors && composer require wgirhad/geophp:^3.0 && composer global exec phar-composer build -v)", + "cp /tmp/vendors/vendors.phar ./Resources/Private/geophp.phar", + "(VERSION=$(git tag --sort=taggerdate | tail -1) && zip -r ../ods_osm-$VERSION.zip *)" + ] } }