diff --git a/cosmogramme/php/_menu.php b/cosmogramme/php/_menu.php index a10bbac8b9329cae9ecbb521f38339c0ff6962ec..92abaecade6dc93aa1c1594a2dc722b5c880ff40 100644 --- a/cosmogramme/php/_menu.php +++ b/cosmogramme/php/_menu.php @@ -126,7 +126,6 @@ else ligneMenu("Logs des erreurs SQL","integre_log_sql.php"); ligneMenu("Réindexation des identifiants","util_indexation.php"); ligneMenu("Réindexation phonétique","util_fulltext.php?action=PARAM"); - ligneMenu("Traitements ponctuels","util_divers.php"); ?> </body> </html> diff --git a/cosmogramme/php/classes/classe_abonne.php b/cosmogramme/php/classes/classe_abonne.php index d82e0488b8fb5a9855167e9d5c8bb8d4fc41a92b..5356b07ee20c77336ce36b6ab5547f5e99f50266 100644 --- a/cosmogramme/php/classes/classe_abonne.php +++ b/cosmogramme/php/classes/classe_abonne.php @@ -64,10 +64,21 @@ class abonne else $this->importFicheAscii($data); } + + public function clean_email($email) { + $email = trim($email); + $email = str_replace(" ", "", $email); + $email = preg_replace("#[\;\#\n\r\*\'\"<>&\%\!\(\)\{\}\[\]\?\\/\s]#", "", $email); + return $email; + } + + // ---------------------------------------------------------------- // Import d'une fiche en ASCII // ---------------------------------------------------------------- public function importFicheAscii($data) { + xdebug_break(); + // Transco accents $data=$this->changeAccents($data); $enreg['MAIL'] = ''; @@ -79,7 +90,6 @@ class abonne $enreg[$colonne]=$data[$i]; } - $this->importFicheArray(array_filter($enreg)); } @@ -99,7 +109,7 @@ class abonne if(!$enreg["PASSWORD"] and $enreg["NAISSANCE"]) $enreg["PASSWORD"]=rendDate($enreg["NAISSANCE"],1); - + $enreg['MAIL']=$this->clean_email($enreg['MAIL']); $this->saveorUpdateInDB($enreg); } @@ -116,10 +126,11 @@ class abonne foreach($this->champs as $champ => $balise) { if($balise){ $cmd="\$enreg['$champ']=(string)\$data->".addslashes($balise).";"; - eval($cmd); + $balise=addslashes($balise); + $enreg[$champ]=(string)$data->$balise; } } - + $enreg['MAIL']=$this->clean_email($enreg['MAIL']); $enreg = $this->prepareData($enreg); $this->saveOrUpdateInDB($enreg); } diff --git a/cosmogramme/php/classes/classe_sql.php b/cosmogramme/php/classes/classe_sql.php index 13e867cca6825fa435b74f5e986f5be9cdd4b9c7..d62a90e750c009aa9eb17b27182d71e8d6144ebc 100644 --- a/cosmogramme/php/classes/classe_sql.php +++ b/cosmogramme/php/classes/classe_sql.php @@ -144,9 +144,10 @@ class sql $statement = isset($this->statements[$table][$cols]) ? $this->statements[$table][$cols] : $this->statements[$table][$cols] = $this->createInsertPrepareStatement($table, $data); - - foreach($data as $col => $valeur) - $statement->bindParam(":$col", trim($valeur)); + + foreach($data as $col => $valeur) { + $statement->bindValue(":$col", trim($valeur)); + } try { $result = $statement->execute(); diff --git a/cosmogramme/php/integre_generation_pergame.php b/cosmogramme/php/integre_generation_pergame.php index ac873ca2cf53ad176b8a2c3de2521c2745cf7594..003328ee020fbcf66a7efafb5264af3825deff5e 100644 --- a/cosmogramme/php/integre_generation_pergame.php +++ b/cosmogramme/php/integre_generation_pergame.php @@ -143,8 +143,8 @@ if($_REQUEST["action"]=="CONTROLE") sqlExecute("delete from int_bib where id_bib=".$enreg["ID_SITE"]); $enreg1["id_bib"]=$enreg["ID_SITE"]; - $enreg1["nom"]=$enreg["LIBELLE"]; - $enreg1["nom_court"]=$enreg["LIBELLE"]; + $enreg1["nom"]=trim($enreg["LIBELLE"]); + $enreg1["nom_court"]=trim($enreg["LIBELLE"]); $enreg1["qualite"]=5; $enreg1["sigb"]=$type_sigb; $enreg1["planif_mode"]="r"; @@ -160,7 +160,8 @@ if($_REQUEST["action"]=="CONTROLE") $enreg1["comm_sigb"]=1; $enreg1["comm_params"]=serialize(array("Autoriser_docs_disponibles"=>"0","Max_par_carte"=>"3","Max_par_document"=>"3")); } - sqlInsert("int_bib", $enreg1); + + (new Class_IntBib)->updateAttributes($enreg1)->save(); $nb_bibs++; } print('</table></div>'); @@ -216,7 +217,7 @@ if($_REQUEST["action"]=="CONTROLE") $enreg["type_operation"]=1; $enreg["nom_fichier"]=$path_fichier."site".$id_bib."/suppressions.txt"; $enreg["rang"]=$id_prog; - sqlInsert("int_maj_auto", $enreg); + (new Class_IntMajAuto)->updateAttributes($enreg)->save(); } // notices total @@ -229,7 +230,8 @@ if($_REQUEST["action"]=="CONTROLE") $enreg["type_operation"]=2; $enreg["nom_fichier"]=$path_fichier."site".$id_bib."/notices_total.txt"; $enreg["rang"]=$id_prog; - sqlInsert("int_maj_auto", $enreg); + (new Class_IntMajAuto)->updateAttributes($enreg)->save(); + // notices incrémentiel echo '<tr><td class="blank"> </td><td class="blank">Import incrémentiel des notices</td></tr>'; @@ -241,7 +243,7 @@ if($_REQUEST["action"]=="CONTROLE") $enreg["type_operation"]=0; $enreg["nom_fichier"]=$path_fichier."site".$id_bib."/notices.txt"; $enreg["rang"]=$id_prog; - sqlInsert("int_maj_auto", $enreg); + (new Class_IntMajAuto)->updateAttributes($enreg)->save(); // abonnés echo '<tr><td class="blank"> </td><td class="blank">Import des abonnés</td></tr>'; @@ -253,7 +255,7 @@ if($_REQUEST["action"]=="CONTROLE") $enreg["type_operation"]=2; $enreg["nom_fichier"]=$path_fichier."site".$id_bib."/abonnes.txt"; $enreg["rang"]=$id_prog; - sqlInsert("int_maj_auto", $enreg); + (new Class_IntMajAuto)->updateAttributes($enreg)->save(); // prêts echo '<tr><td class="blank"> </td><td class="blank">Import des prêts</td></tr>'; @@ -264,7 +266,7 @@ if($_REQUEST["action"]=="CONTROLE") $enreg["type_operation"]=2; $enreg["nom_fichier"]=$path_fichier."site".$id_bib."/prets.txt"; $enreg["rang"]=$id_prog; - sqlInsert("int_maj_auto", $enreg); + (new Class_IntMajAuto)->updateAttributes($enreg)->save(); // réservations (pergame uniquement) if($type_sigb==1) @@ -277,7 +279,7 @@ if($_REQUEST["action"]=="CONTROLE") $enreg["type_operation"]=2; $enreg["nom_fichier"]=$path_fichier."site".$id_bib."/reservations.txt"; $enreg["rang"]=$id_prog; - sqlInsert("int_maj_auto", $enreg); + (new Class_IntMajAuto)->updateAttributes($enreg)->save(); } } print('</table></div>'); diff --git a/cosmogramme/tests/php/classes/AbonneIntegrationTest.php b/cosmogramme/tests/php/classes/AbonneIntegrationTest.php index 723e48d3e6fc2940e4df6d22472ebbc2e680d7a0..e9fefd3d1cf4811aecdd6235ff68cd99860c36bc 100644 --- a/cosmogramme/tests/php/classes/AbonneIntegrationTest.php +++ b/cosmogramme/tests/php/classes/AbonneIntegrationTest.php @@ -64,10 +64,6 @@ abstract class AbonneIntegrationXMLTestCase extends AbonneIntegrationTestCase { public function setup(){ parent::setup(); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') - ->whenCalled('save') - ->answers(true); - $this->abon_config->setChamps(['IDABON'=>'LECTNUM', 'ID_SIGB'=>'LECTNUM', @@ -207,7 +203,7 @@ class AbonneIntegrationASCIIWithRoutoInDbTest extends AbonneIntegrationTestCase 'Routo', 'Pierre', 'la', - 'rp@afi-sa.fr']); + '"rp@afi-sa.fr "']); $this->abon_config->importFicheAscii($champs_sigb_ascii); @@ -215,12 +211,17 @@ class AbonneIntegrationASCIIWithRoutoInDbTest extends AbonneIntegrationTestCase $this->users = Class_Users::findAllBy(['login' => '5 5']); } - + /** @test */ public function onlyOneUserShouldHaveLogin55() { $this->assertEquals(1, count($this->users)); } + /** @test */ + public function mailShouldBeCleaned() { + $this->assertEquals('rp@afi-sa.fr',$this->users[0]->getMail()); + } + /** @test **/ public function withRoutoInDbImportShouldUpdateRoutoWithIdabon55() { $this->assertEquals('5 5',$this->users[0]->getIdabon()); @@ -271,6 +272,8 @@ class AbonneIntegrationASCIIWithTwoUsersSameLoginDifferentPasswordAndOrdreAbonTe $jsmith2 = Class_Users::findFirstBy(['login' => 'jsmith', 'ordreabon' => 2]); $this->assertEquals('1977-06-25', $jsmith2->getNaissance()); + $this->assertEquals('js@afi-sa.fr', $jsmith2->getMail()); + } @@ -341,7 +344,8 @@ class AbonneIntegrationASCIIWithIDSigbInDataAndNotInBaseTest extends AbonneInteg $this->abon_config->importFicheArray(['IDABON' => 'jsmith', 'NOM' => 'johnny', - 'ID_SIGB' => 24]); + 'ID_SIGB' => 24, + 'MAIL' => ' " jsmith!@nomail.org "']); $this->johny = Class_Users::findFirstBy(['id_sigb' => 24]); } @@ -361,6 +365,12 @@ class AbonneIntegrationASCIIWithIDSigbInDataAndNotInBaseTest extends AbonneInteg public function userWithIdFourShouldBeJohnny() { $this->assertEquals('johnny', Class_Users::find(4)->getNom()); } + + /** @test */ + public function mailJohnnyShouldBeCleaned() { + $this->assertEquals('jsmith@nomail.org',$this->johny->getMail()); + } + } @@ -374,7 +384,7 @@ class AbonneIntegrationXMLWithNoUsersInDbTest extends AbonneIntegrationXMLTestCa $champs_sigb_xml = '<Item><TYPE_ABONNE>I</TYPE_ABONNE><LECTNUM>00003090</LECTNUM><LASTNAME>Pirly</LASTNAME><FIRSTNAME>Coco</FIRSTNAME><FULLNAME>Pirly, Coco</FULLNAME><DATEBIRTH>12/31/1982</DATEBIRTH><MOT_DE_PASSE>zoom</MOT_DE_PASSE></Item>'; $this->abon_config->importFicheXml($champs_sigb_xml); - $this->user_tom = Class_Users::getFirstAttributeForLastCallOn('save'); + $this->user_tom = Class_Users::findFirstBy(['nom'=> 'Pirly']); } @@ -395,21 +405,19 @@ class AbonneIntegrationXMLWithRoutoInDbTest extends AbonneIntegrationXMLTestCase public function setup(){ parent::setup(); - $this->user_zozio = Class_Users::newInstanceWithId(5,['nom'=>'poirreau', - 'prenom'=>'Zozio', - 'login'=>'01003080', - 'password'=>'allez les bleus']); + $this->user_zozio = $this->fixture('Class_Users',['id'=>5, + 'nom'=>'poirreau', + 'prenom'=>'Zozio', + 'login'=>'01003080', + 'password'=>'allez les bleus']); - Class_Users::whenCalled('findFirstBy') - ->with(['login'=>'0100 3080', - 'id_site'=>2]) - ->answers($this->user_zozio); - - $champs_sigb_xml = '<Item><TYPE_ABONNE>I</TYPE_ABONNE><LECTNUM>0100 3080</LECTNUM><LASTNAME>poirreau</LASTNAME><FIRSTNAME>Zozio</FIRSTNAME><FULLNAME>Piou Piou</FULLNAME><DATEBIRTH>12/31/2012</DATEBIRTH><MOT_DE_PASSE>allez les bleus</MOT_DE_PASSE></Item>'; + + $champs_sigb_xml = '<Item><TYPE_ABONNE>I</TYPE_ABONNE><LECTNUM>0100 3080</LECTNUM><LASTNAME>poirreau</LASTNAME><FIRSTNAME>Zozio</FIRSTNAME><FULLNAME>Piou Piou</FULLNAME><DATEBIRTH>12/31/2012</DATEBIRTH><MOT_DE_PASSE>poum</MOT_DE_PASSE><EMAIL>" ##zozio@nomail.org "</EMAIL></Item>'; $this->abon_config->importFicheXml($champs_sigb_xml); - $this->zozio_after_import = Class_Users::getFirstAttributeForLastCallOn('save'); + $this->zozio_after_import = Class_Users::findFirstby(['login'=>'0100 3080', + 'id_site' => 2]); } /** @test **/ @@ -419,8 +427,14 @@ class AbonneIntegrationXMLWithRoutoInDbTest extends AbonneIntegrationXMLTestCase /** @test **/ - public function routoInDbAndRoutoAfterImportShouldBeTheSame() { - $this->assertSame($this->user_zozio, $this->zozio_after_import); + public function passwordAfterImportXmlShouldBePoum() { + $this->assertEquals('poum', $this->zozio_after_import->getPassword()); + } + + /** @test */ + public function mailImportXmlShouldBeCleaned() { + $this->assertEquals('zozio@nomail.org',$this->zozio_after_import->getMail()); } + } diff --git a/library/Class/IntMajAuto.php b/library/Class/IntMajAuto.php new file mode 100644 index 0000000000000000000000000000000000000000..2b6da0f462e664ca9af7a8d0bb6d0d6dae79c2d4 --- /dev/null +++ b/library/Class/IntMajAuto.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class Class_IntMajAuto extends Storm_Model_Abstract { + protected $_table_name = 'int_maj_auto'; + protected $_table_primary = 'id_prog'; +} + +?> \ No newline at end of file