diff --git a/.gitattributes b/.gitattributes index 3463ce94b5e3ac18ae12fe0df772924f9ec4ad72..895d844d53ed9982d1b193b5b349b22fa7301724 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4908,6 +4908,7 @@ public/telephone/skins/original/templates/boites/boite_de_la_division_du_milieu. public/telephone/skins/original/templates/boites/boite_de_la_division_gauche.html -text /robots.txt -text scripts/find_tests.php -text +scripts/import_sitotheque.php -text scripts/insert_licence.sh -text scripts/iosrd.sh -text scripts/marker-visit.el -text diff --git a/scripts/import_sitotheque.php b/scripts/import_sitotheque.php new file mode 100644 index 0000000000000000000000000000000000000000..7e9370b5a47e2ef629b4f503860a5a109af84f8d --- /dev/null +++ b/scripts/import_sitotheque.php @@ -0,0 +1,78 @@ +<?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 + */ +chdir(realpath(dirname(__FILE__)).'/../'); +define("BASE_URL", "/"); + +set_include_path('.' . PATH_SEPARATOR . './library' + . PATH_SEPARATOR . '../ZendFramework-1.6.2/library' + . PATH_SEPARATOR . get_include_path()); + +include_once "local.php"; +include_once "fonctions/fonctions.php"; +require_once "Zend/Loader.php"; +require_once "library/startup.php"; + +setupOpac(); + +$sites = Class_Sitotheque::findAll(); +foreach($sites as $site) + $site->delete(); + +$root_categories = Class_SitothequeCategorie::findAllBy(['id_cat_mere' => 0]); +foreach($root_categories as $cat) + $cat->delete(); + + +$handle = fopen('sitotheque.csv', 'r'); +while (($line = fgetcsv($handle, 0, ';')) !== FALSE) { + xdebug_break(); + $path = '/'.$line[0].'/'.$line[1].'/'.$line[2]; + + if (!$domaine = Class_SitothequeCategorie::findFirstBy(['id_cat_mere' => 0, + 'libelle' => $line[0]])) { + $domaine = Class_SitothequeCategorie::newInstance(['libelle' => $line[0]]); + $domaine->save(); + } + + if (!$categorie = $domaine->findByPath('/'.$line[1])) { + $categorie = Class_SitothequeCategorie::newInstance(['libelle' => $line[1], + 'parent_categorie' => $domaine]); + $categorie->save(); + } + + + if (!$sous_categorie = $categorie->findByPath('/'.$line[2])) { + $sous_categorie = Class_SitothequeCategorie::newInstance(['libelle' => $line[2], + 'parent_categorie' => $categorie]); + $sous_categorie->save(); + } + + + $catalogue = Class_Catalogue::findWithSamePathAs($sous_categorie); + $site = Class_Sitotheque::newInstance(['titre' => $line[3], + 'description' => $line[4], + 'url' => $line[5], + 'domaine_ids' => $catalogue ? $catalogue->getId() : '', + 'categorie' => $sous_categorie]); + $site->saveWithoutValidation(); + echo '+ '.$site->getUrl().' :: '.$sous_categorie->getPath().'/'.$site->getTitre()."\n"; +} +?> \ No newline at end of file