From 81c2fcffadc280611a24a1be2fc952c5f9109014 Mon Sep 17 00:00:00 2001 From: eki89 Date: Tue, 7 Feb 2023 18:14:39 +0100 Subject: [PATCH 01/11] Import adjustments --- src/Resources/contao/dca/tl_real_estate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/contao/dca/tl_real_estate.php b/src/Resources/contao/dca/tl_real_estate.php index 406ca17..0bef7c9 100644 --- a/src/Resources/contao/dca/tl_real_estate.php +++ b/src/Resources/contao/dca/tl_real_estate.php @@ -219,7 +219,7 @@ 'sql' => "varchar(64) NOT NULL default ''" ), - // Objektkategorien + // Objektkategorien 'nutzungsart' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_real_estate']['nutzungsart'], From d107fe713e0ad8ca93bdea7b27482973cf5aead0 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 10:26:55 +0100 Subject: [PATCH 02/11] [Bugfix] Do not generate a real-estate alias if no title exists --- src/Resources/contao/dca/tl_real_estate.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Resources/contao/dca/tl_real_estate.php b/src/Resources/contao/dca/tl_real_estate.php index 0bef7c9..5b7637f 100644 --- a/src/Resources/contao/dca/tl_real_estate.php +++ b/src/Resources/contao/dca/tl_real_estate.php @@ -5238,6 +5238,13 @@ public function generateAlias($varValue, $dc, string $title=''): string if (!$varValue) { $title = $dc->activeRecord !== null ? $dc->activeRecord->objekttitel : $title; + + // Do not generate an alias if no title is given + if (empty($title)) + { + return ''; + } + $varValue = Contao\System::getContainer()->get('contao.slug.generator')->generate($title); } From 7c99694141d196f28dee2e034fe05f680d09e70b Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 11:53:15 +0100 Subject: [PATCH 03/11] [Update] Enable importing modified files with the same filename via cron --- src/Resources/contao/classes/RealEstateCronImporter.php | 2 +- src/Resources/contao/classes/RealEstateImporter.php | 9 +++++++++ src/Resources/contao/dca/tl_interface_history.php | 4 ++++ src/Resources/contao/models/InterfaceHistoryModel.php | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Resources/contao/classes/RealEstateCronImporter.php b/src/Resources/contao/classes/RealEstateCronImporter.php index 89b2184..4babc8c 100644 --- a/src/Resources/contao/classes/RealEstateCronImporter.php +++ b/src/Resources/contao/classes/RealEstateCronImporter.php @@ -87,7 +87,7 @@ protected function sync($objInterface) foreach ($syncFiles as $syncFile) { - if (null === $syncFile['synctime']) + if ((null === $syncFile['synctime']) || $syncFile['modified']) { $files[] = $syncFile; } diff --git a/src/Resources/contao/classes/RealEstateImporter.php b/src/Resources/contao/classes/RealEstateImporter.php index f74fc10..d73ca36 100644 --- a/src/Resources/contao/classes/RealEstateImporter.php +++ b/src/Resources/contao/classes/RealEstateImporter.php @@ -855,6 +855,7 @@ protected function updateCatalog($contactPersonRecords, $realEstateRecords) $objInterfaceHistory->pid = $this->objInterface->id; $objInterfaceHistory->tstamp = time(); $objInterfaceHistory->source = $this->originalSyncFile; + $objInterfaceHistory->mtime = FilesHelper::fileModTime($this->originalSyncFile); $objInterfaceHistory->action = ''; $objInterfaceHistory->username = $this->username; $objInterfaceHistory->text = $this->importMessage; @@ -949,6 +950,13 @@ public function getSyncFiles($searchForZip=true) } }*/ + // If the file with the same name has been found but was modified + $modified = + array_key_exists($file, $arrSynced) && // Only if it previously existed + (0 !== intval($arrSynced[$file]->mtime)) && // Do not reimport pre-update files (< 1.0.29) + $mtime !== intval($arrSynced[$file]->mtime) // Only if file has been modified + ; + $arrFiles[] = array( "file" => $file, "time" => $mtime, @@ -956,6 +964,7 @@ public function getSyncFiles($searchForZip=true) "user" => array_key_exists($file, $arrSynced) ? $arrSynced[$file]->username : null, "status" => array_key_exists($file, $arrSynced) ? intval($arrSynced[$file]->status) : 0, "synctime" => array_key_exists($file, $arrSynced) ? intval($arrSynced[$file]->tstamp) : null, + "modified" => $modified, "checked" => false ); } diff --git a/src/Resources/contao/dca/tl_interface_history.php b/src/Resources/contao/dca/tl_interface_history.php index e0231cb..f785688 100644 --- a/src/Resources/contao/dca/tl_interface_history.php +++ b/src/Resources/contao/dca/tl_interface_history.php @@ -90,6 +90,10 @@ 'flag' => 6, 'sql' => "int(10) unsigned NOT NULL default '0'" ), + 'mtime' => array + ( + 'sql' => "int(10) unsigned NOT NULL default '0'" + ), 'source' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_interface_history']['source'], diff --git a/src/Resources/contao/models/InterfaceHistoryModel.php b/src/Resources/contao/models/InterfaceHistoryModel.php index c8d29aa..8dd1296 100644 --- a/src/Resources/contao/models/InterfaceHistoryModel.php +++ b/src/Resources/contao/models/InterfaceHistoryModel.php @@ -19,6 +19,7 @@ * @property integer $id * @property integer $pid * @property integer $tstamp + * @property integer $mtime * @property string $source * @property string $action * @property string $username @@ -30,6 +31,7 @@ * @method static InterfaceHistoryModel|null findOneBy($col, $val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByPid($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByTstamp($val, array $opt=array()) + * @method static InterfaceHistoryModel|null findOneByMtime($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneBySource($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByAction($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByUsername($val, array $opt=array()) @@ -38,6 +40,7 @@ * * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByPid($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByTstamp($val, array $opt=array()) + * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByMtime($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findBySource($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByAction($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByUsername($val, array $opt=array()) @@ -50,6 +53,7 @@ * @method static integer countById($id, array $opt=array()) * @method static integer countByPid($val, array $opt=array()) * @method static integer countByTstamp($val, array $opt=array()) + * @method static integer countByMtime($val, array $opt=array()) * @method static integer countBySource($val, array $opt=array()) * @method static integer countByAction($val, array $opt=array()) * @method static integer countByUsername($val, array $opt=array()) From e26a50e6d66de529f280c7f9c11e1cf395955c7c Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 11:54:01 +0100 Subject: [PATCH 04/11] [Change] Make property title non-mandatory (objekttitel) --- src/Resources/contao/dca/tl_real_estate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/contao/dca/tl_real_estate.php b/src/Resources/contao/dca/tl_real_estate.php index 5b7637f..bdd52c1 100644 --- a/src/Resources/contao/dca/tl_real_estate.php +++ b/src/Resources/contao/dca/tl_real_estate.php @@ -2272,7 +2272,7 @@ 'inputType' => 'text', 'search' => true, 'flag' => 1, - 'eval' => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=> 'w50'), + 'eval' => array('maxlength'=>255, 'tl_class'=> 'w50'), 'sql' => "varchar(255) NOT NULL default ''", ), 'objektbeschreibung' => array From 20ba3e88cb982a310a594650a14d48c78c887558 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 14:30:24 +0100 Subject: [PATCH 05/11] [Update] Skip broken import files on cron import - the cron import will not stop completely when a faulty import has been detected - the cron import will now log an error in the backend - unless a faulty import file has been modified (modDate), it will not be considered by the cronjob anymore - updated tl_interface_history to quickly download the broken import file - highlight import errors within tl_interface_history --- .../contao/classes/RealEstateImporter.php | 76 +++++++++++++++---- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/src/Resources/contao/classes/RealEstateImporter.php b/src/Resources/contao/classes/RealEstateImporter.php index d73ca36..ef0d498 100644 --- a/src/Resources/contao/classes/RealEstateImporter.php +++ b/src/Resources/contao/classes/RealEstateImporter.php @@ -12,6 +12,7 @@ use Contao\BackendTemplate; +use Contao\CoreBundle\Monolog\ContaoContext; use Contao\Database; use Contao\Dbafs; use Contao\Files; @@ -21,6 +22,9 @@ use Contao\StringUtil; use Contao\System; use Contao\ZipReader; +use Exception; +use Psr\Log\LogLevel; +use Throwable; class RealEstateImporter extends \BackendModule { @@ -362,9 +366,18 @@ public function startSync($syncFile='') if (($this->loadData())) { + try + { + $this->syncData(); + } + catch (Throwable $e) + { + $this->handleImportError($e); + } + //$this->addLog('OpenImmo data loaded', 1, 'success'); - if ($this->syncData()) + /*if ($this->syncData()) { //$this->addLog('Import and synchronization was successful', 0, 'success'); //\Message::addConfirmation('Import and synchronization was successful'); @@ -373,7 +386,7 @@ public function startSync($syncFile='') { //$this->addLog('OpenImmo data could not be synchronized.', 0, 'error'); //\Message::addError('OpenImmo data could not be synchronized.'); - } + }*/ } else { @@ -843,7 +856,7 @@ protected function updateCatalog($contactPersonRecords, $realEstateRecords) try { $tmpFolder = new Folder($this->objImportFolder->path . '/tmp'); - } catch (\Exception $e) { + } catch (Exception $e) { return; } @@ -851,15 +864,21 @@ protected function updateCatalog($contactPersonRecords, $realEstateRecords) $tmpFolder->purge(); // Create history entry - $objInterfaceHistory = new InterfaceHistoryModel(); - $objInterfaceHistory->pid = $this->objInterface->id; - $objInterfaceHistory->tstamp = time(); - $objInterfaceHistory->source = $this->originalSyncFile; - $objInterfaceHistory->mtime = FilesHelper::fileModTime($this->originalSyncFile); - $objInterfaceHistory->action = ''; + + // In case file already existed before but has been skipped due to an error + if (null === ($objInterfaceHistory = InterfaceHistoryModel::findBySource($this->originalSyncFile))) + { + $objInterfaceHistory = new InterfaceHistoryModel(); + $objInterfaceHistory->pid = $this->objInterface->id; + $objInterfaceHistory->source = $this->originalSyncFile; + } + + $objInterfaceHistory->tstamp = time(); + $objInterfaceHistory->mtime = FilesHelper::fileModTime($this->originalSyncFile); + $objInterfaceHistory->action = ''; $objInterfaceHistory->username = $this->username; - $objInterfaceHistory->text = $this->importMessage; - $objInterfaceHistory->status = $this->importStatus; + $objInterfaceHistory->text = $this->importMessage; + $objInterfaceHistory->status = $this->importStatus; $objInterfaceHistory->save(); return true; @@ -887,7 +906,7 @@ protected function loadData() try { $this->data = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } @@ -905,7 +924,7 @@ public function getSyncFiles($searchForZip=true) { try { $folder = new Folder($this->objImportFolder->path); - } catch (\Exception $e) { + } catch (Exception $e) { return array(); } @@ -986,7 +1005,7 @@ public function getSyncFile($file) $this->addLog('File is empty.', 0, 'error'); // Delete empty file - try{ unlink(TL_ROOT . '/' . $file); }catch (\Exception $exception){} + try{ unlink(TL_ROOT . '/' . $file); }catch (Exception $exception){} return false; } @@ -1018,13 +1037,13 @@ public function getSyncFile($file) * * @param string $path path to zip file * - * @throws \Exception + * @throws Exception */ public function unzipArchive($path) { try { $tmpFolder = new Folder(FilesHelper::fileDirPath($path) . 'tmp'); - } catch (\Exception $e) { + } catch (Exception $e) { return; } @@ -1465,6 +1484,31 @@ protected function getTableMetaData($strTable) return $arrReturn; } + /** + * Handles import errors by logging the error and disabling the file for the next import + */ + private function handleImportError(string $e): void + { + $errorMsg = 'The real estate file: ' . $this->originalSyncFile . '. Error: ' . $e; + $logger = static::getContainer()->get('monolog.logger.contao'); + $logger->log(LogLevel::ERROR, $errorMsg, array('contao' => new ContaoContext(__METHOD__, 'ERROR'))); + + if (null === ($objInterfaceHistory = InterfaceHistoryModel::findBySource($this->originalSyncFile))) + { + $objInterfaceHistory = new InterfaceHistoryModel(); + $objInterfaceHistory->pid = $this->objInterface->id; + $objInterfaceHistory->source = $this->originalSyncFile; + } + + $objInterfaceHistory->tstamp = time(); + $objInterfaceHistory->mtime = FilesHelper::fileModTime($this->originalSyncFile); + $objInterfaceHistory->username = $this->username; + $objInterfaceHistory->text = 'File has been skipped: ' . $this->originalSyncFile . ''; + $objInterfaceHistory->status = 2; + $objInterfaceHistory->action = 'ERROR'; + $objInterfaceHistory->save(); + } + public function addLog($strMessage, $level=0, $strType='raw', $data=null) { // ToDo: In Datei auslagern From dbe2b61a310572adbd7becc98d7b2279f9a4f763 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 15:19:42 +0100 Subject: [PATCH 06/11] [Update] Log error message within interface_history - logs details of the error message within an interface history item for better access --- .../contao/classes/RealEstateImporter.php | 9 ++++++--- .../contao/dca/tl_interface_history.php | 6 ++++++ .../contao/languages/de/tl_interface_history.xlf | 16 ++++++++++++++++ .../contao/languages/en/tl_interface_history.xlf | 12 ++++++++++++ .../contao/models/InterfaceHistoryModel.php | 4 ++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/Resources/contao/classes/RealEstateImporter.php b/src/Resources/contao/classes/RealEstateImporter.php index ef0d498..2a2977f 100644 --- a/src/Resources/contao/classes/RealEstateImporter.php +++ b/src/Resources/contao/classes/RealEstateImporter.php @@ -372,7 +372,7 @@ public function startSync($syncFile='') } catch (Throwable $e) { - $this->handleImportError($e); + $this->handleImportError($e->getMessage()); } //$this->addLog('OpenImmo data loaded', 1, 'success'); @@ -878,6 +878,7 @@ protected function updateCatalog($contactPersonRecords, $realEstateRecords) $objInterfaceHistory->action = ''; $objInterfaceHistory->username = $this->username; $objInterfaceHistory->text = $this->importMessage; + $objInterfaceHistory->message = ''; $objInterfaceHistory->status = $this->importStatus; $objInterfaceHistory->save(); @@ -1354,6 +1355,7 @@ protected function saveImage($interfaceMapping, $tmpGroup, &$value, &$values) return false; } + // ToDo: Add import limit from estatemanager settings $fileSize = FilesHelper::fileSize($this->objImportFolder->path . '/tmp/' . $value); if ($fileSize > 3000000 || $fileSize === 0) { @@ -1487,9 +1489,9 @@ protected function getTableMetaData($strTable) /** * Handles import errors by logging the error and disabling the file for the next import */ - private function handleImportError(string $e): void + private function handleImportError(string $message): void { - $errorMsg = 'The real estate file: ' . $this->originalSyncFile . '. Error: ' . $e; + $errorMsg = 'The real estate file: ' . $this->originalSyncFile . ' could not be imported.'; $logger = static::getContainer()->get('monolog.logger.contao'); $logger->log(LogLevel::ERROR, $errorMsg, array('contao' => new ContaoContext(__METHOD__, 'ERROR'))); @@ -1504,6 +1506,7 @@ private function handleImportError(string $e): void $objInterfaceHistory->mtime = FilesHelper::fileModTime($this->originalSyncFile); $objInterfaceHistory->username = $this->username; $objInterfaceHistory->text = 'File has been skipped: ' . $this->originalSyncFile . ''; + $objInterfaceHistory->message = $message; $objInterfaceHistory->status = 2; $objInterfaceHistory->action = 'ERROR'; $objInterfaceHistory->save(); diff --git a/src/Resources/contao/dca/tl_interface_history.php b/src/Resources/contao/dca/tl_interface_history.php index f785688..3576689 100644 --- a/src/Resources/contao/dca/tl_interface_history.php +++ b/src/Resources/contao/dca/tl_interface_history.php @@ -123,6 +123,12 @@ 'search' => true, 'sql' => "text NULL" ), + 'message' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_interface_history']['message'], + 'search' => true, + 'sql' => "text NULL" + ), 'status' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_interface_history']['username'], diff --git a/src/Resources/contao/languages/de/tl_interface_history.xlf b/src/Resources/contao/languages/de/tl_interface_history.xlf index f4f0b12..aa31289 100644 --- a/src/Resources/contao/languages/de/tl_interface_history.xlf +++ b/src/Resources/contao/languages/de/tl_interface_history.xlf @@ -9,6 +9,14 @@ Date and time of the log entry Datum und Uhrzeit des Eintrags + + Modification date + Datei-Änderungsdatum + + + Date and time of the last file modification + Datum und Uhrzeit der letzten Dateiänderung. + Origin Ursprung @@ -41,6 +49,14 @@ Details of the log entry Details des Log-Eintrags + + Message + Nachricht + + + Details of the log message + Details der Log-Nachricht + Show details Anzeigen diff --git a/src/Resources/contao/languages/en/tl_interface_history.xlf b/src/Resources/contao/languages/en/tl_interface_history.xlf index ce02299..711331e 100644 --- a/src/Resources/contao/languages/en/tl_interface_history.xlf +++ b/src/Resources/contao/languages/en/tl_interface_history.xlf @@ -7,6 +7,12 @@ Date and time of the log entry + + Modification date + + + Date and time of the last file modification + Origin @@ -31,6 +37,12 @@ Details of the log entry + + Message + + + Details of the log message + Show details diff --git a/src/Resources/contao/models/InterfaceHistoryModel.php b/src/Resources/contao/models/InterfaceHistoryModel.php index 8dd1296..41316cf 100644 --- a/src/Resources/contao/models/InterfaceHistoryModel.php +++ b/src/Resources/contao/models/InterfaceHistoryModel.php @@ -24,6 +24,7 @@ * @property string $action * @property string $username * @property string $text + * @property string $message * @property integer $status * * @method static InterfaceHistoryModel|null findById($id, array $opt=array()) @@ -36,6 +37,7 @@ * @method static InterfaceHistoryModel|null findOneByAction($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByUsername($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByText($val, array $opt=array()) + * @method static InterfaceHistoryModel|null findOneByMessage($val, array $opt=array()) * @method static InterfaceHistoryModel|null findOneByStatus($val, array $opt=array()) * * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByPid($val, array $opt=array()) @@ -45,6 +47,7 @@ * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByAction($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByUsername($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByText($val, array $opt=array()) + * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByMessage($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findByStatus($val, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findMultipleByIds($var, array $opt=array()) * @method static Collection|InterfaceHistoryModel[]|InterfaceHistoryModel|null findBy($col, $val, array $opt=array()) @@ -58,6 +61,7 @@ * @method static integer countByAction($val, array $opt=array()) * @method static integer countByUsername($val, array $opt=array()) * @method static integer countByText($val, array $opt=array()) + * @method static integer countByMessage($val, array $opt=array()) * @method static integer countByStatus($val, array $opt=array()) * * @author Daniele Sciannimanica From 8eebce07f93c67568d9f2728beaba26ce9f74703 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 16:45:02 +0100 Subject: [PATCH 07/11] [Update] Add new salutations and rewrite letter salutation - 'family', 'company', 'spouses', 'not applicable', 'diverse' --- .../contao/data/import_interface_mappings.php | 2 +- .../contao/dca/tl_contact_person.php | 32 +++++++++--- .../contao/languages/de/tl_contact_person.xlf | 52 +++++++++++++++++++ .../contao/languages/en/tl_contact_person.xlf | 45 ++++++++++++++++ .../modules/ExposeModuleContactPerson.php | 1 + 5 files changed, 123 insertions(+), 9 deletions(-) diff --git a/src/Resources/contao/data/import_interface_mappings.php b/src/Resources/contao/data/import_interface_mappings.php index 78e24f0..2b78216 100644 --- a/src/Resources/contao/data/import_interface_mappings.php +++ b/src/Resources/contao/data/import_interface_mappings.php @@ -24,7 +24,7 @@ array('tl_contact_person', 'vorname', 'kontaktperson', 'vorname'), array('tl_contact_person', 'titel', 'kontaktperson', 'titel'), array('tl_contact_person', 'position', 'kontaktperson', 'position'), - array('tl_contact_person', 'anrede', 'kontaktperson', 'anrede'), + array('tl_contact_person', 'anrede', 'kontaktperson', 'anrede', array('text', 'lowercase')), array('tl_contact_person', 'anrede_brief', 'kontaktperson', 'anrede_brief'), array('tl_contact_person', 'firma', 'kontaktperson', 'firma'), array('tl_contact_person', 'strasse', 'kontaktperson', 'strasse'), diff --git a/src/Resources/contao/dca/tl_contact_person.php b/src/Resources/contao/dca/tl_contact_person.php index 54ee36b..04a9d12 100644 --- a/src/Resources/contao/dca/tl_contact_person.php +++ b/src/Resources/contao/dca/tl_contact_person.php @@ -126,10 +126,10 @@ 'label' => &$GLOBALS['TL_LANG']['tl_contact_person']['anrede'], 'exclude' => true, 'inputType' => 'select', - 'options' => array('herr','frau'), + 'options' => array('herr', 'frau', 'firma', 'eheleute', 'familie', 'nicht zutreffend', 'divers'), 'reference' => &$GLOBALS['TL_LANG']['tl_contact_person'], 'eval' => array('tl_class'=>'w50'), - 'sql' => "varchar(8) NOT NULL default ''" + 'sql' => "varchar(16) NOT NULL default ''" ), 'firma' => array ( @@ -563,15 +563,31 @@ public function stringifyContactPerson(array $arrRow): string public function generateSalutation(string $varValue, Contao\DataContainer $dc): string { // Generate salutation if there is none - if ($varValue == '') + if ('' == $varValue) { - if($dc->activeRecord->anrede == 'herr'){ - $salutation = &$GLOBALS['TL_LANG']['tl_contact_person']['salutationMr'][0]; - }else{ - $salutation = &$GLOBALS['TL_LANG']['tl_contact_person']['salutationMrs'][0]; + $prefix = &$GLOBALS['TL_LANG']['tl_contact_person']['salutationGlobal'][0]; + $prefix2 = null; + + switch ($salutation = $dc->activeRecord->anrede) + { + case 'herr': + $prefix = &$GLOBALS['TL_LANG']['tl_contact_person']['salutationMr'][0]; + $prefix2 = &$GLOBALS['TL_LANG']['tl_contact_person'][$salutation][1]; + break; + + case 'frau': + $prefix = &$GLOBALS['TL_LANG']['tl_contact_person']['salutationMrs'][0]; + $prefix2 = &$GLOBALS['TL_LANG']['tl_contact_person'][$salutation][1]; + break; + + case 'eheleute': + case 'familie': + case 'firma': + $prefix2 = &$GLOBALS['TL_LANG']['tl_contact_person'][$salutation][1]; + break; } - $varValue = $salutation . ' ' . $GLOBALS['TL_LANG']['tl_contact_person'][$dc->activeRecord->anrede][0] . ' ' . ($dc->activeRecord->titel ? $dc->activeRecord->titel . ' ' : '') . $dc->activeRecord->vorname . ' ' . $dc->activeRecord->name; + $varValue = $prefix . ($prefix2 ? ' '. $prefix2 : '') . ' ' . ($dc->activeRecord->titel ? $dc->activeRecord->titel . ' ' : '') . $dc->activeRecord->vorname . ' ' . $dc->activeRecord->name; } return $varValue; diff --git a/src/Resources/contao/languages/de/tl_contact_person.xlf b/src/Resources/contao/languages/de/tl_contact_person.xlf index cf281d2..d59c427 100644 --- a/src/Resources/contao/languages/de/tl_contact_person.xlf +++ b/src/Resources/contao/languages/de/tl_contact_person.xlf @@ -13,10 +13,58 @@ Mr. Herr + + Mr. + Herr + Mrs. Frau + + Mrs. + Frau + + + Company + Firma + + + Company + Firma + + + Spouses + Eheleute + + + spouses + Eheleute + + + Family + Familie + + + family + Familie + + + Not applicable + Nicht zutreffend + + + + + + + Diverse + Divers + + + + + Dear Sehr geehrter @@ -25,6 +73,10 @@ Dear Sehr geehrte + + Dear + Guten Tag + Company diff --git a/src/Resources/contao/languages/en/tl_contact_person.xlf b/src/Resources/contao/languages/en/tl_contact_person.xlf index 68e49be..68b4fe4 100644 --- a/src/Resources/contao/languages/en/tl_contact_person.xlf +++ b/src/Resources/contao/languages/en/tl_contact_person.xlf @@ -11,15 +11,60 @@ Mr. + + Mr. + Mrs. + + Mrs. + + + Mr. + + + Mr. + + + Company + + + Company + + + Spouses + + + spouses + + + Family + + + family + + + Not applicable + + + + + + Diverse + + + + Dear Dear + + Dear + Company diff --git a/src/Resources/contao/modules/ExposeModuleContactPerson.php b/src/Resources/contao/modules/ExposeModuleContactPerson.php index c8287a8..5e2cd37 100644 --- a/src/Resources/contao/modules/ExposeModuleContactPerson.php +++ b/src/Resources/contao/modules/ExposeModuleContactPerson.php @@ -75,6 +75,7 @@ protected function compile() $varSingleSrc = Config::get('defaultContactPersonFemaleImage'); break; case 'herr': + case 'herrn': $varSingleSrc = Config::get('defaultContactPersonMaleImage'); break; } From 501c76bd78315df2e5801d64ba8c45b9ead3010f Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 16:46:55 +0100 Subject: [PATCH 08/11] [Addition] Add field formatting for 'security system' (Fixes #181) --- src/Resources/contao/data/import_field_formats.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Resources/contao/data/import_field_formats.php b/src/Resources/contao/data/import_field_formats.php index ec4678c..2586f2f 100644 --- a/src/Resources/contao/data/import_field_formats.php +++ b/src/Resources/contao/data/import_field_formats.php @@ -968,5 +968,13 @@ ( array('combine', '', '', ' ', '', 'a:2:{i:0;a:2:{s:5:"field";s:3:"ort";s:6:"remove";s:1:"1";}i:1;a:2:{s:5:"field";s:16:"regionalerZusatz";s:6:"remove";s:1:"1";}}', '') ) - ) -); \ No newline at end of file + ), + array + ( + 'field' => array('sicherheitstechnik', '', '', NULL), + 'actions' => array + ( + array('unserialize', '', '', ', ', '', NULL, '') + ) + ), +); From 5919755d1e496a06aa30b9f9d85bde656807027b Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 17:16:44 +0100 Subject: [PATCH 09/11] [Addition] Enable overriding the maximum image filesize when importing --- src/Resources/contao/classes/RealEstateImporter.php | 8 +++++--- src/Resources/contao/config/config.php | 1 + src/Resources/contao/dca/tl_real_estate_config.php | 9 ++++++++- .../contao/languages/de/tl_real_estate_config.xlf | 12 ++++++++++++ .../contao/languages/en/tl_real_estate_config.xlf | 10 +++++++++- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Resources/contao/classes/RealEstateImporter.php b/src/Resources/contao/classes/RealEstateImporter.php index 2a2977f..1d264b9 100644 --- a/src/Resources/contao/classes/RealEstateImporter.php +++ b/src/Resources/contao/classes/RealEstateImporter.php @@ -12,6 +12,7 @@ use Contao\BackendTemplate; +use Contao\Config; use Contao\CoreBundle\Monolog\ContaoContext; use Contao\Database; use Contao\Dbafs; @@ -1355,9 +1356,10 @@ protected function saveImage($interfaceMapping, $tmpGroup, &$value, &$values) return false; } - // ToDo: Add import limit from estatemanager settings - $fileSize = FilesHelper::fileSize($this->objImportFolder->path . '/tmp/' . $value); - if ($fileSize > 3000000 || $fileSize === 0) + $fileSize = FilesHelper::fileSize($this->objImportFolder->path . '/tmp/' . $value); + $maxUpload = Config::get('estateManagerMaxFileSize') ?? 3000000; + + if ($fileSize > $maxUpload || $fileSize === 0) { return false; } diff --git a/src/Resources/contao/config/config.php b/src/Resources/contao/config/config.php index efb0f24..f058f4a 100644 --- a/src/Resources/contao/config/config.php +++ b/src/Resources/contao/config/config.php @@ -193,3 +193,4 @@ $GLOBALS['TL_CONFIG']['numberFormatDecimals'] = ','; $GLOBALS['TL_CONFIG']['numberFormatThousands'] = '.'; $GLOBALS['TL_CONFIG']['roomOptions'] = '1,2,3,4,5,6,7,8'; +$GLOBALS['TL_CONFIG']['estateManagerMaxFileSize'] = 3000000; diff --git a/src/Resources/contao/dca/tl_real_estate_config.php b/src/Resources/contao/dca/tl_real_estate_config.php index 7afb8e6..6685940 100644 --- a/src/Resources/contao/dca/tl_real_estate_config.php +++ b/src/Resources/contao/dca/tl_real_estate_config.php @@ -24,7 +24,7 @@ // Palettes 'palettes' => array ( - 'default' => '{global_legend},estateManagerAdminEmail;{real_estate_list_legend},defaultSorting,statusTokenNewDisplayDuration,defaultNumberOfMainDetails,defaultNumberOfMainAttr,defaultImage;{provider_contact_legend},defaultContactPersonImage,defaultContactPersonFemaleImage,defaultContactPersonMaleImage;{number_legend:hide},numberFormatDecimals,numberFormatThousands;{filter_config_legend:hide},roomOptions' + 'default' => '{global_legend},estateManagerAdminEmail;{real_estate_list_legend},defaultSorting,statusTokenNewDisplayDuration,defaultNumberOfMainDetails,defaultNumberOfMainAttr,defaultImage;{provider_contact_legend},defaultContactPersonImage,defaultContactPersonFemaleImage,defaultContactPersonMaleImage;{number_legend:hide},numberFormatDecimals,numberFormatThousands;{filter_config_legend:hide},roomOptions;{import_legend:hide},estateManagerMaxFileSize' ), // Fields @@ -125,5 +125,12 @@ 'inputType' => 'text', 'eval' => array('mandatory'=>true, 'rgxp'=>'natural', 'tl_class'=>'w50') ), + 'estateManagerMaxFileSize' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_real_estate_config']['maxFileSize'], + 'default' => '3000000', + 'inputType' => 'text', + 'eval' => array('mandatory'=>true, 'rgxp'=>'natural', 'nospace'=>true, 'tl_class'=>'w50') + ), ) ); diff --git a/src/Resources/contao/languages/de/tl_real_estate_config.xlf b/src/Resources/contao/languages/de/tl_real_estate_config.xlf index d5e0122..30acdcb 100644 --- a/src/Resources/contao/languages/de/tl_real_estate_config.xlf +++ b/src/Resources/contao/languages/de/tl_real_estate_config.xlf @@ -21,6 +21,10 @@ Provider / Contact Persons Anbieter / Kontaktpersonen + + Import + Import + E-mail address of the technical administrator @@ -110,6 +114,14 @@ Here you can enter a comma separated list of options which should be available for the number of rooms. Hier können Sie die eine kommagetrente Liste von Optionen eingeben, die für die Zimmeranzahl zur Verfügung stehen soll. + + Maximum image upload file size + Maximale Bild-Upload-Dateigröße + + + Here you can enter the maximum upload file size in bytes (1 MB = 1000 kB = 1000000 byte). + Hier können Sie die maximale Upload-Dateigröße in Bytes eingeben (1 MB = 1000 kB = 1000000 Byte). + Date added diff --git a/src/Resources/contao/languages/en/tl_real_estate_config.xlf b/src/Resources/contao/languages/en/tl_real_estate_config.xlf index f41509f..08c8350 100644 --- a/src/Resources/contao/languages/en/tl_real_estate_config.xlf +++ b/src/Resources/contao/languages/en/tl_real_estate_config.xlf @@ -17,7 +17,9 @@ Provider / Contact Persons - + + Import + E-mail address of the technical administrator @@ -84,6 +86,12 @@ Here you can enter a comma separated list of options which should be available for the number of rooms. + + Maximum image upload file size + + + Here you can enter the maximum upload file size in bytes (1 MB = 1000 kB = 1000000 byte). + Date added From 7b28e3d737f6b3be02991e1548441d4f0cdf9ec0 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 19:37:45 +0100 Subject: [PATCH 10/11] [Addition] Add download links to interface overview - download links for each file - added title attribute with error information --- src/Resources/contao/classes/RealEstateImporter.php | 13 +++++++------ .../templates/backend/be_real_estate_sync.html5 | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Resources/contao/classes/RealEstateImporter.php b/src/Resources/contao/classes/RealEstateImporter.php index 1d264b9..74a49fc 100644 --- a/src/Resources/contao/classes/RealEstateImporter.php +++ b/src/Resources/contao/classes/RealEstateImporter.php @@ -979,14 +979,15 @@ public function getSyncFiles($searchForZip=true) ; $arrFiles[] = array( - "file" => $file, - "time" => $mtime, - "size" => $size, - "user" => array_key_exists($file, $arrSynced) ? $arrSynced[$file]->username : null, - "status" => array_key_exists($file, $arrSynced) ? intval($arrSynced[$file]->status) : 0, + "file" => $file, + "time" => $mtime, + "size" => $size, + "user" => array_key_exists($file, $arrSynced) ? $arrSynced[$file]->username : null, + "status" => array_key_exists($file, $arrSynced) ? intval($arrSynced[$file]->status) : 0, "synctime" => array_key_exists($file, $arrSynced) ? intval($arrSynced[$file]->tstamp) : null, + "message" => array_key_exists($file, $arrSynced) ? $arrSynced[$file]->message : null, "modified" => $modified, - "checked" => false + "checked" => false ); } diff --git a/src/Resources/contao/templates/backend/be_real_estate_sync.html5 b/src/Resources/contao/templates/backend/be_real_estate_sync.html5 index 9c799a8..0f9434a 100644 --- a/src/Resources/contao/templates/backend/be_real_estate_sync.html5 +++ b/src/Resources/contao/templates/backend/be_real_estate_sync.html5 @@ -31,7 +31,7 @@
 
- + > From 21a248b4fe2c9d159afad8ce357cf2ede3c8ff99 Mon Sep 17 00:00:00 2001 From: Sebastian Zoglowek Date: Tue, 21 Feb 2023 20:21:11 +0100 Subject: [PATCH 11/11] [Update] Consider partially imported files and save the error message --- src/Resources/contao/classes/RealEstateImporter.php | 8 +++++++- .../contao/templates/backend/be_real_estate_sync.html5 | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Resources/contao/classes/RealEstateImporter.php b/src/Resources/contao/classes/RealEstateImporter.php index 74a49fc..46cb3e7 100644 --- a/src/Resources/contao/classes/RealEstateImporter.php +++ b/src/Resources/contao/classes/RealEstateImporter.php @@ -125,6 +125,11 @@ class RealEstateImporter extends \BackendModule */ public $importMessage = 'File imported.'; + /** + * @var string + */ + public $errorMessage = ''; + /** * @var boolean */ @@ -448,6 +453,7 @@ protected function syncData() { $this->importStatus = 2; $this->importMessage = 'File partially imported.'; + $this->errorMessage = 'File was partially imported as no provider could be found'; continue; } @@ -879,7 +885,7 @@ protected function updateCatalog($contactPersonRecords, $realEstateRecords) $objInterfaceHistory->action = ''; $objInterfaceHistory->username = $this->username; $objInterfaceHistory->text = $this->importMessage; - $objInterfaceHistory->message = ''; + $objInterfaceHistory->message = $this->errorMessage; $objInterfaceHistory->status = $this->importStatus; $objInterfaceHistory->save(); diff --git a/src/Resources/contao/templates/backend/be_real_estate_sync.html5 b/src/Resources/contao/templates/backend/be_real_estate_sync.html5 index 0f9434a..c21b5f7 100644 --- a/src/Resources/contao/templates/backend/be_real_estate_sync.html5 +++ b/src/Resources/contao/templates/backend/be_real_estate_sync.html5 @@ -31,7 +31,7 @@
 
- > +