From 3ac02f50d921345e45876d6b1d740fee7f2ad996 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Fri, 13 Apr 2018 13:14:41 +0100 Subject: [PATCH] FEAT refactoring + indexes by department --- referential/ban/indexBan.php | 40 +++++++++++-------- .../contact/controllers/ContactController.php | 8 ++-- src/core/lang/lang-fr.php | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/referential/ban/indexBan.php b/referential/ban/indexBan.php index ff1d70b581f..1d35b5b6a19 100644 --- a/referential/ban/indexBan.php +++ b/referential/ban/indexBan.php @@ -1,22 +1,9 @@ <?php require '../../vendor/autoload.php'; -$indexFileDirectory = __DIR__ . '/indexes/'; $banDirectory = __DIR__ . '/src/'; $filesBan = scandir($banDirectory); -if (!is_dir($indexFileDirectory)) { - $index = Zend_Search_Lucene::create($indexFileDirectory); -} else { - if (isDirEmpty($indexFileDirectory)) { - $index = Zend_Search_Lucene::create($indexFileDirectory); - } else { - $index = Zend_Search_Lucene::open($indexFileDirectory); - } -} -$index->setFormatVersion(Zend_Search_Lucene::FORMAT_2_3); -Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()); -$index->setMaxBufferedDocs(1000); $row = 1; foreach ($filesBan as $fileBan) { @@ -24,6 +11,28 @@ foreach ($filesBan as $fileBan) { echo "$fileBan\n"; $duplicateAddresses = []; $currentCity = ''; + + // Create Folder by department + $folderName = str_replace("BAN_licence_gratuite_repartage_", "", $fileBan); + $folderName = str_replace(".csv", "", $folderName); + $folderName = __DIR__ . '/indexes/'.$folderName; + if (!is_dir($folderName)) { + mkdir($folderName); + } + + // if (!is_dir($folderName)) { + // $index = Zend_Search_Lucene::create($folderName); + // } else { + if (isDirEmpty($folderName)) { + $index = Zend_Search_Lucene::create($folderName); + } else { + $index = Zend_Search_Lucene::open($folderName); + } + // } + $index->setFormatVersion(Zend_Search_Lucene::FORMAT_2_3); + Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()); + $index->setMaxBufferedDocs(1000); + $i = 1; while (($data = fgetcsv($handle, 0, ";")) !== false) { if ($i == 1) { @@ -60,13 +69,12 @@ foreach ($filesBan as $fileBan) { $row++; } fclose($handle); + $index->commit(); + $index->optimize(); } } echo date('c'); -$index->commit(); -$index->optimize(); - /** * Check if a folder is empty * @param $dir string path of the directory to chek diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php index 3777e9efd15..892186c7b6e 100644 --- a/src/app/contact/controllers/ContactController.php +++ b/src/app/contact/controllers/ContactController.php @@ -82,7 +82,7 @@ class ContactController return $response->withJson([$contact]); } - public function formatContactAddressAfnor(array $aArgs) + public static function formatContactAddressAfnor(array $aArgs) { $formattedAddress = ''; @@ -125,12 +125,12 @@ class ContactController // $formattedAddress .= "\n"; // Ligne 6 - $formattedAddress .= substr($aArgs['address_postal_code'] . ' ' . $aArgs['address_town'], 0, 38) . "\n"; + $formattedAddress .= substr($aArgs['address_postal_code'] . ' ' . $aArgs['address_town'], 0, 38); return $formattedAddress; } - public function controlLengthNameAfnor(array $aArgs) + public static function controlLengthNameAfnor(array $aArgs) { $aCivility = ContactController::getContactCivility(); if (strlen($aArgs['title'] . ' ' . $aArgs['fullName']) > $aArgs['strMaxLength']) { @@ -142,7 +142,7 @@ class ContactController return substr($aArgs['title'] . ' ' . $aArgs['fullName'], 0, $aArgs['strMaxLength']); } - public function getContactCivility() + public static function getContactCivility() { $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/entreprise.xml']); diff --git a/src/core/lang/lang-fr.php b/src/core/lang/lang-fr.php index 0be75b96a41..d03ca028233 100644 --- a/src/core/lang/lang-fr.php +++ b/src/core/lang/lang-fr.php @@ -73,7 +73,7 @@ define('_USER_ENTITY_MODIFICATION', 'Entité modifiée pour utilisateur'); define('_USER_ENTITY_SUPPRESSION', 'Entité supprimée pour utilisateur'); define('_VISA_USER', 'Pour visa'); define('_WRONG_FILE_TYPE', 'Ce type de fichier n\'est pas permis'); -define('_CAN_NOT_MOVE_IN_CHILD_ENTITY', 'L\'entité parente de doit pas être une entité fille'); +define('_CAN_NOT_MOVE_IN_CHILD_ENTITY', 'L\'entité parente ne doit pas être dans une entité fille'); define('_DOCUMENTS_LIST_WITH_ATTACHMENTS', 'Liste avec filtres et réponses'); define('_DOCUMENTS_LIST_WITH_AVIS', 'Liste des documents avec avis'); -- GitLab