Skip to content

Commit

Permalink
[BUGFIX] Include geoPHP as Phar into TER package
Browse files Browse the repository at this point in the history
  • Loading branch information
albig committed Apr 24, 2024
1 parent dbaf5aa commit 9ddb60f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ package-lock.json

/var
/config

Resources/Private/geophp.phar
25 changes: 24 additions & 1 deletion Classes/TceMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)"
]
}
}

0 comments on commit 9ddb60f

Please sign in to comment.