Changeset aafb30d


Ignore:
Timestamp:
08/23/10 14:17:27 (21 months ago)
Author:
Benoit Grégoire <benoitg@…>
Branches:
('master', '8434b8322dd6f8ff37c17bd45b94e7a826f86b53')('vitrine', 'afe109c61a407808bd54d88bcccb1cde726a010a')
Children:
f4e524f46ba145b3a6938dad4e9babdcfac160bf
Parents:
e0e292f0315a09d924cdb2910962574fdaef290e
git-author:
Benoit Grégoire <benoitg@coeus.ca>2010-08-23 14:17:27-04:00
git-committer:
Benoit Grégoire <benoitg@coeus.ca>2010-08-23 14:17:27-04:00
Message:

MUCH faster vocabulary import code

Location:
html
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • html/admin/vocabulary_admin.php

    r9f704d6 raafb30d  
    278278 
    279279                    $vocabulary = new Vocabulary('NEW'); 
    280                     $num_imported_terms = $vocabulary->import($dom, $format); 
    281                     if ($num_imported_terms == 0) 
     280                    $importResults = $vocabulary->import($dom, $format); 
     281                    if ($importResults === false) 
    282282                    { 
    283283 
    284                         echo _("No terms imported, importation failed; Erasing the vocabulary<br/>"); 
     284                        echo _("Importation failed; Erasing the vocabulary<br/>"); 
    285285                        $vocabulary->delete(); 
    286286                    } 
    287287                    else 
    288288                    { 
    289                         echo sprintf(ngettext("%d vocabulary term has been added.", "%d vocabulary terms have been added.", $num_imported_terms), $num_imported_terms)."<br/>"; 
     289                        echo sprintf(ngettext("%d new vocabulary term has been added (%d updated).", "%d new vocabulary terms have been added  (%d updated).",$importResults['new']), $importResults['new'], $importResults['updated'])."<br/>"; 
    290290                    } 
    291291                } 
  • html/classes/Langstring.php

    r3550449 raafb30d  
    3030define('LANGSTRING_BUTTON_ADD_NEW_VALUE', 'Ajouter une chaîne supplémentaire'); 
    3131 
    32 /** Représente un Langstring en particulier, ne créez pas un objet langstrings si wous n'en avez pas spécifiquement besoin  
     32/** Représente un Langstring en particulier, ne créez pas un objet langstrings si wous n'en avez pas spécifiquement besoin 
    3333 */ 
    3434class Langstring extends GenericDataObject 
     
    3636 
    3737    /** Returns the cached string in the class-wide cache, or null in no cached value exists 
    38      * @param $langstring_id The id of the langstring for which we ask a cached 
     38     * @param $langstring_id int The id of the langstring for which we ask a cached 
    3939     * value */ 
    4040    static private function getCachedString($langstring_id, $locale) 
     
    8989 
    9090    /**Constructeur 
    91      @param id Clef maitresse du langstring ou "NEW" pour créer un nouveau LangString dans la base de donnée.   
     91     @param id Clef maitresse du langstring ou "NEW" pour créer un nouveau LangString dans la base de donnée. 
    9292     */ 
    9393    function __construct($id = null) 
     
    217217            $string = $this->mBd->EscapeString($string); 
    218218            $this->mBd->execSqlUpdate("INSERT INTO langstring_entries (langstrings_id, locales_id, value) VALUES ('$this->mId', $id , '$string')", false); 
     219            $this->dirtyCachedString(); 
    219220            $retval = true; 
    220221        } 
     
    248249            try 
    249250            { 
    250                 $this->mBd->executerSqlResUnique("SELECT * FROM langstring_entries WHERE  locales_id {$equality_operator} {$id} AND langstrings_id = '$this->mId'", $row, false); 
    251                 if ($row != null) 
    252                 { 
    253                     $string = $this->mBd->EscapeString($string); 
    254                     $this->mBd->execSqlUpdate("UPDATE langstring_entries SET value = '$string' WHERE langstrings_id = '$this->mId' AND locales_id = $id", false); 
     251                    $this->mBd->executerSqlResUnique("SELECT * FROM langstring_entries WHERE  locales_id {$equality_operator} {$id} AND langstrings_id = '$this->mId'", $row, false); 
     252                    if ($row != null) { 
     253                        if ($row['value'] != $string) { 
     254                            $string = $this->mBd->EscapeString($string); 
     255                            $this->mBd->execSqlUpdate("UPDATE langstring_entries SET value = '$string' WHERE langstrings_id = '$this->mId' AND locales_id = $id", false); 
     256                        } 
     257                        $this->dirtyCachedString(); 
     258                    } 
     259                    else             { 
     260                        $this->addString($string, $locale); 
     261                    } 
    255262                    $retval = true; 
    256                 } 
    257                 else 
    258                 { 
    259                     $this->addString($string, $locale); 
    260                     $retval = true; 
    261  
    262                 } 
    263263            } 
    264264            catch (Exception $e) 
     
    273273    /**Affiche l'interface d'administration de l'objet 
    274274     @param type_interface SIMPLE pour éditer un seul champ, COMPLETE pour voir toutes les chaînes, LARGE pour avoir un textarea. 
    275      @param num_nouveau Nombre de champ à afficher pour entrer de nouvelles chaîne en une seule opération.  Si 0, il n'y aura un nouveau  
     275     @param num_nouveau Nombre de champ à afficher pour entrer de nouvelles chaîne en une seule opération.  Si 0, il n'y aura un nouveau 
    276276     champ que s'il n'y a pas déjà une sous-chaîne. 
    277277     */ 
  • html/classes/Vocabulary.php

    rf533742 raafb30d  
    461461var termsArray = new Array($termsCount+1); 
    462462termsArray[0]='---'; 
    463 $jsTerms 
     463                $jsTerms 
    464464                                //alert("New length: " + termsArray.length) 
    465465</script> 
    466466EOT; 
    467 echo $script; 
    468  
    469 foreach ($vocabulary_terms_result as $vocabulary_terms_row) 
    470 { 
    471     $term = VocabularyTerm::getObject(array ($vocabulary_terms_row['vdex_6_1_identifier'], $this->mId)); 
    472     $term->displayAdminUI(); 
    473 } 
     467                echo $script; 
     468 
     469                foreach ($vocabulary_terms_result as $vocabulary_terms_row) 
     470                { 
     471                    $term = VocabularyTerm::getObject(array ($vocabulary_terms_row['vdex_6_1_identifier'], $this->mId)); 
     472                    $term->displayAdminUI(); 
     473                } 
    474474            } 
    475475 
     
    729729     format VDEX : DOMDocument object 
    730730     @param $format string either CSV_array or VDEX 
    731      @return Le nombre d'entrées (terme) ajoutées dans la base de donnée 
     731     @return array array('new'=>$inserted_terms, 'updated'=>$updated_terms) Le nombre d'entrées (terme) ajoutées dans la base de donnée, ===false if failed 
    732732     */ 
    733733    function import($data, $format, $debug = false) 
    734734    { 
    735735        //$debug=true; 
    736         $inserted_terms = 0; 
     736        $retval = array('new'=>0, 'updated'=>0); 
    737737        if ($format == 'CSV_array') 
    738738        { 
     
    753753                    pretty_print_r($pk); 
    754754                    $this->mBd->execSqlUpdate("INSERT INTO vocabulary_terms (vdex_4_vocabulary_identifier, caption ,identifier) VALUES (".$this->getSqlId().", ".$langstring->getId().", $pk)", false); 
    755                     $inserted_terms ++; 
     755                    $retval['new']++; 
    756756                } 
    757757            } 
     
    930930 
    931931                // Création du nouveau vocabulaire 
    932                 // Note: la source à l'importation est une copîe de vdex_4_vocabulary_identifier 
     932                // Note: la source à l'importation est une copie de vdex_4_vocabulary_identifier 
    933933                $this->mBd->ExecuterSqlResUnique("INSERT INTO vocabularies (vdex_1_order_significant, vdex_2_profile_type, vdex_3_vocabulary_name, vdex_4_vocabulary_identifier, vdex_4_1_registration_status, vdex_5_default_language, vocabulary_source, is_system_vocabulary, is_relationship_vocabulary) 
    934934                                                                                                                                VALUES ($vdex_1_order_significant, $vdex_2_profile_type, $vdex_3_vocabulary_name, '$vdex_4_vocabulary_identifier', $vdex_4_1_registration_status, $vdex_5_default_language, '$vocabulary_source', $is_system_vocabulary, $is_relationship_vocabulary); 
     
    946946            foreach ($terms_list as $term) 
    947947            { 
    948                 $inserted_terms ++; 
    949948                $node_list = $xpath->query("dns:termIdentifier", $term); 
    950949                foreach ($node_list as $node) 
     
    967966                        echo "The term $vdex_6_1_identifier is missing, importing it !<br/>"; 
    968967                        $vocabulary_term = new VocabularyTerm(array ('0' => 'NEW', '1' => $this->mId), $vdex_6_1_identifier, null); 
    969                         $vocabulary_term->import($term, $format, $data, $debug); 
     968                        $retval['new']++; //For the term itself 
    970969                    } 
    971970                    else 
    972971                    { 
    973                         // Update this term 
     972                        // Update the term 
    974973                        if ($debug) 
    975974                        echo "The term $vdex_6_1_identifier already exists, updating it !<br/>"; 
    976975                        $vocabulary_term = VocabularyTerm::getObject(array ('0' => $vdex_6_1_identifier, '1' => $this->mId)); 
    977                         $vocabulary_term->import($term, $format, $data, $debug); 
     976                        $retval['updated']++; //For the term itself 
    978977                    } 
    979978                } 
     
    981980                { 
    982981                    $vocabulary_term = new VocabularyTerm(array ('0' => 'NEW', '1' => $this->mId), $vdex_6_1_identifier, null); 
    983                     $vocabulary_term->import($term, $format, $data, $debug); 
    984                 } 
     982                    $retval['new']++; //For the term itself 
     983                } 
     984                $importResult = $vocabulary_term->import($term, $format, $data, $debug); 
     985                if($importResult===false){ 
     986                    throw new Exception ("Failed importing a term"); 
     987                } 
     988                $retval['new']+=$importResult['new']; 
     989                $retval['updated']+=$importResult['updated']; 
    985990            } 
    986991 
    987992            /* 7 Relationship :: 0 - n*/ 
    988993            $relationships_list = $xpath->query("//dns:vdex/dns:relationship"); 
     994            $currentRelationshipsIdArray=array(); 
    989995            if($debug){ 
    990996                echo "\n Found {$relationships_list->length} relationship(s)"; 
     
    10461052        else { 
    10471053            echo '<h1>ERROR: Vocabulary::import(); $format = '.$format.' Format inconnu!</h1>'; 
    1048         } 
    1049         return $inserted_terms; 
     1054            $retval=false; 
     1055        } 
     1056        return $retval; 
    10501057    } 
    10511058 
  • html/classes/VocabularyTerm.php

    r9f704d6 raafb30d  
    108108 
    109109    /** Constructeur 
    110     @param $id_array An array:  $id_array[0]=vdex_6_1_identifier ou NEW pour ajouter une nouvelle entrée 
     110    @param $id_array array:  $id_array[0]=vdex_6_1_identifier ou NEW pour ajouter une nouvelle entrée 
    111111    $id_array[1]=vdex_4_vocabulary_identifier (l'identifiant du vocabulaire auquel le terme appartient) 
    112112    or 
    113113    $id_array[1]=array(vdex_4_vocabulary_identifier, vdex_4_vocabulary_identifier, ...) to look for the term in more than one voc 
    114     @param $id_new If $id_array[0]='NEW', must contain the specific id of the new term 
     114    @param $id_new string If $id_array[0]='NEW', must contain the specific id of the new term 
    115115    @param $parent_id DEPRECATED and ignored 
    116116    @param $allow_vdex_update, Allow automatic VDEX download for update 
     
    285285    } 
    286286 
    287     /** Indique si la clef primaire de l'objet  est une chaîne de caractÚre.  
     287    /** Indique si la clef primaire de l'objet  est une chaîne de caractÚre. 
    288288     */ 
    289289    static function primaryKeyIsString() 
     
    314314    { 
    315315        return Langstring::getObject($this->mRow['vdex_6_3_caption']); 
     316    } 
     317 
     318    /** 
     319     * @return boolean 
     320     */ 
     321    public function getIsValidIndex() { 
     322        return $this->mRow['vdex_6_2_valid_index']=='t'?true:false; 
     323    } 
     324 
     325    /** 
     326     * @return boolean 
     327     */ 
     328    public function getIsOrderSignificant() { 
     329        return $this->mRow['vdex_6_6_order_significant']=='t'?true:false; 
    316330    } 
    317331 
     
    474488    } 
    475489 
    476     /** Retourne le thÚme parent de celui-ci  
     490    /** Retourne le thÚme parent de celui-ci 
    477491     * @return Retourne le parent, un objet de même type que celui qui a été 
    478492     * instancié ou null si le terme est à la racine 
     
    497511    } 
    498512 
    499     /* Retourne la hiérarchie de termes au dessus de celui-ci, en commençant pas la racine  
     513    /* Retourne la hiérarchie de termes au dessus de celui-ci, en commençant pas la racine 
    500514     * @param = $include_self=false 
    501515     * @return array de VocabularyTerm représentant le chemin d'accÚs de cet entré thésaurus 
     
    10451059     @param $export_format format de la sortie:  LOM ou VDEX 
    10461060     @param $document Le document auquel la sortie doit être ajouté.  Le type peut varier 
    1047      @param $parent Le parent de l'élément à ajouter.  Le type peut varier    
     1061     @param $parent Le parent de l'élément à ajouter.  Le type peut varier 
    10481062     @param $entree ID de l'entree de Vocabulary 
    10491063     */ 
     
    11561170     @param $document DOMDocument where the node comes from 
    11571171     @debug activate debug 
    1158      @return true si résussi  
     1172     @return  array array('new'=>$inserted_terms, 'updated'=>$updated_terms) number of new inserted or updated >subterms< (could be 0).  ===false if failed 
    11591173     */ 
    11601174    function import($data, $format, $document, $debug = false) 
     
    11621176        $sql = "SELECT * FROM vocabulary_terms NATURAL JOIN vocabularies WHERE vdex_6_1_identifier=".$this->getSqlId().""; 
    11631177        $this->mBd->executerSqlResUnique($sql, $vocabulary_terms_row, false); 
    1164  
     1178        $retval = array('new'=>0, 'updated'=>0); 
     1179        $sqlUpdatesArray = array(); 
    11651180        if ($vocabulary_terms_row != null) 
    11661181        { 
     
    11741189                if ($debug) 
    11751190                echo "{$attr->nodeName}={$attr->nodeValue}<br/>"; 
    1176                 $vdex_6_2_valid_index = $this->mBd->EscapeString($attr->nodeValue); 
    1177                 $sql = "UPDATE vocabulary_terms SET vdex_6_2_valid_index = $vdex_6_2_valid_index WHERE  vdex_6_1_identifier=".$this->getSqlId().";\n"; 
    1178                 $this->mBd->execSqlUpdate($sql, false); 
     1191                $value = $attr->nodeValue=='true'?true:false; 
     1192                $sqlValue = $this->mBd->EscapeString($attr->nodeValue); 
     1193                if($this->getIsValidIndex()!=$value) { 
     1194                    $sqlUpdatesArray[] = "vdex_6_2_valid_index = $sqlValue"; 
     1195                } 
    11791196            } 
    11801197 
     
    12531270                if ($debug) 
    12541271                echo "{$attr->nodeName}={$attr->nodeValue}<br/>"; 
    1255                 $vdex_6_6_order_significant = $this->mBd->EscapeString($attr->nodeValue); 
    1256                 $sql = "UPDATE vocabulary_terms SET vdex_6_6_order_significant = $vdex_6_6_order_significant WHERE  vdex_6_1_identifier=".$this->getSqlId().";\n"; 
    1257                 $this->mBd->execSqlUpdate($sql, false); 
     1272                $value = $attr->nodeValue=='true'?true:false; 
     1273                $sqlValue = $this->mBd->EscapeString($attr->nodeValue); 
     1274                if($this->getIsOrderSignificant()!=$value) { 
     1275                    $sqlUpdatesArray[] = "vdex_6_6_order_significant = $sqlValue"; 
     1276                } 
    12581277            } 
    12591278 
     
    12831302                    echo "The term $vdex_6_1_identifier is missing, importing it !<br/>"; 
    12841303                    $vocabulary_term = new VocabularyTerm(array ('0' => 'NEW', '1' => $this->mId[1]), $vdex_6_1_identifier, array ('0' => $this->mId[0], '1' => $this->mId[1])); 
    1285                     $vocabulary_term->import($term, $format, $document, $debug); 
     1304                    $retval['new']++; 
    12861305                } 
    12871306                else 
     
    12911310                    echo "The term $vdex_6_1_identifier already exists, updating it !<br/>"; 
    12921311                    $vocabulary_term = VocabularyTerm::getObject(array ('0' => $vdex_6_1_identifier, '1' => $this->mId[1])); 
    1293                     $vocabulary_term->import($term, $format, $document, $debug); 
    1294                 } 
    1295  
    1296             } 
    1297             return true; 
     1312                    $retval['updated']++; 
     1313                } 
     1314                $importResult = $vocabulary_term->import($term, $format, $document, $debug); 
     1315                if($importResult===false){ 
     1316                    throw new Exception ("Failed importing a term"); 
     1317                } 
     1318                $retval['new']+=$importResult['new']; 
     1319                $retval['updated']+=$importResult['updated']; 
     1320            } 
     1321            if (!empty($sqlUpdatesArray)){ 
     1322                $updates = implode(", ", $sqlUpdatesArray); 
     1323                $sql = "UPDATE vocabulary_terms SET $updates WHERE  vdex_6_1_identifier=".$this->getSqlId().";\n"; 
     1324                $this->mBd->execSqlUpdate($sql, false); 
     1325                $this->refresh(); 
     1326            } 
     1327            return $retval; 
    12981328        } 
    12991329        else 
     
    13391369    { 
    13401370        $this->DeleteTree(); 
     1371    } 
     1372    /**Met à jour les attributs de l'objet à partir de la base de donnée 
     1373     */ 
     1374    function refresh() 
     1375    { 
     1376        $this->__construct($this->mId); 
    13411377    } 
    13421378 
Note: See TracChangeset for help on using the changeset viewer.