Changeset f4e524f


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

A lot of code changes to try to work around http://bugs.php.net/bug.php?id=52682. Works for now, but will frequently bite us again.

Location:
html
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • html/classes/EurekaUtils.php

    r3550449 rf4e524f  
    138138            { 
    139139                // Removed TLD check to let IP adress pass through \.[a-z]{2,3} 
    140                 if (!eregi("^[0-9a-z]([-.]?[0-9a-z])*$", $splitted_str['host'], $regs)) 
     140                if (!preg_match("/^[0-9a-z]([-.]?[0-9a-z])*$/i", $splitted_str['host'])) 
    141141                { 
    142142                    $errMsg = "host {$splitted_str['host']} not valid"; 
     
    152152            if (array_key_exists('user', $splitted_str)) 
    153153            { 
    154                 if (!eregi("^([0-9a-z-]|[\_])*$", $splitted_str['user'], $regs)) 
     154                if (!preg_match("/^([0-9a-z-]|[\_])*$/i", $splitted_str['user'])) 
    155155                { 
    156156                    $errMsg = "Invalid user {$slitted_str['user']}"; 
     
    161161            if (array_key_exists('pass', $splitted_str)) 
    162162            { 
    163                 if (!eregi("^([0-9a-z-]|[\_])*$", $splitted_str['pass'], $regs)) 
     163                if (!preg_match("/^([0-9a-z-]|[\_])*$/i", $splitted_str['pass'])) 
    164164                { 
    165165                    $errMsg = "Invalid password  {$slitted_str['pass']}"; 
     
    170170            if (array_key_exists('path', $splitted_str)) 
    171171            { 
    172                 if (!eregi("^[0-9a-z/_\.@~\-]*$", $splitted_str['path'], $regs)) 
    173                 { 
    174                     $errMsg = "Invalid path {$slitted_str['path']}"; 
     172                if (!preg_match("/^[0-9a-z\/_\.@~\-]*$/i", $splitted_str['path'])) 
     173                { 
     174                    $errMsg = "Invalid path {$splitted_str['path']}"; 
    175175                    return false; 
    176176                } 
  • html/classes/Langstring.php

    raafb30d rf4e524f  
    246246        if (!empty ($string)) 
    247247        { 
    248             // If the update returns 0 ( no update ), try inserting the record 
    249             try 
    250             { 
    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                     } 
    262                     $retval = true; 
    263             } 
    264             catch (Exception $e) 
    265             { 
    266                 $retval = false; 
    267             } 
     248            
     249            $this->mBd->executerSqlResUnique("SELECT * FROM langstring_entries WHERE  locales_id {$equality_operator} {$id} AND langstrings_id = '$this->mId'", $row, false); 
     250            if ($row != null) { 
     251                if ($row['value'] != $string) { 
     252                    $string = $this->mBd->EscapeString($string); 
     253                    $this->mBd->execSqlUpdate("UPDATE langstring_entries SET value = '$string' WHERE langstrings_id = '$this->mId' AND locales_id = $id", false); 
     254                } 
     255                $this->dirtyCachedString(); 
     256            } 
     257            else { 
     258                 // If we didn't find the row, try inserting the record 
     259                $this->addString($string, $locale); 
     260            } 
     261            $retval = true; 
    268262        } 
    269263        return $retval; 
  • html/classes/Vocabulary.php

    raafb30d rf4e524f  
    145145                } 
    146146                // Try to import from URL, on fail throw an exception 
    147                 if ($this->ImportFromURL($id, $debug) == false) 
    148                 throw new MissingVocabularyException("Vocabulary not found, and unable to import since the id ($id) isn't a URL"); 
     147                $errorMsg = null; 
     148                if ($this->ImportFromURL($id, null, $errorMsg, $debug) == false) 
     149                throw new MissingVocabularyException("Vocabulary not found, and unable to import from id: ($id) because: $errorMsg"); 
    149150            } 
    150151            else 
     
    664665    @param $overrideVocabSource Typically, for vocabularies like LOMFrv.0, where the source isn't a URL 
    665666    */ 
    666     function ImportFromURL($url, $overrideVocabSource = null, $debug = false) 
     667    function ImportFromURL($url, $overrideVocabSource = null, &$errorMsg = null, $debug = false) 
    667668    { 
    668669        $utils = new EurekaUtils(); 
    669         if (EurekaUtils::IsURL($url)) 
     670        $error = null; 
     671        if (EurekaUtils::IsURL($url, $errorMsg)) 
    670672        { 
    671673            if ($debug) 
    672             echo "trying to import from URL<br/>"; 
     674            echo "trying to import from URL $url<br/>"; 
    673675            // The URL exists and the content of the file has been parsed 
    674676            if ($dom = @ DOMDocument :: load($url)) 
     
    687689                    } 
    688690                } 
    689                 else 
    690                 if ($debug) 
    691                 echo "The VDEX did not validate against schema."; 
    692             } 
    693         } 
    694         else 
    695         if ($debug) 
    696         echo "<strong>the URL specified is invalid (should be http:// or ftp://) !</strong><br/>"; 
     691                else { 
     692                    $errorMsg = "The VDEX did not validate against schema."; 
     693                    if ($debug) 
     694                    echo $errorMsg; 
     695                } 
     696            } 
     697            else { 
     698                $errorMsg = "Unable to load or parse XML at URL $url"; 
     699            } 
     700        } 
     701        else { 
     702            if ($debug) 
     703            echo "<strong>the URL specified is invalid ($errorMsg) !</strong><br/>"; 
     704        } 
    697705        return false; 
    698706    } 
     
    10151023                } 
    10161024                $vocabulary_relation = null; 
     1025 
    10171026                if ($updating) { 
    10181027                    try { 
     
    10251034                        } 
    10261035                    } 
    1027                     catch (Exception $e){ 
     1036                    catch (ObjectNotFoundException $e){ 
    10281037                        //Do nothing, it just means the relationship didn't already exist 
    10291038                    } 
     
    10511060        } 
    10521061        else { 
    1053             echo '<h1>ERROR: Vocabulary::import(); $format = '.$format.' Format inconnu!</h1>'; 
    1054             $retval=false; 
     1062            throw ImportException('ERROR: Vocabulary::import(); $format = '.$format.' is unknown!'); 
    10551063        } 
    10561064        return $retval; 
  • html/classes/VocabularyRelation.php

    re0e292f rf4e524f  
    2929require_once 'RelationNN.php'; 
    3030require_once 'Vocabulary.php'; 
     31require_once 'exceptions/ImportException.php'; 
    3132 
    3233error_reporting(E_ALL); 
     
    152153        if ($row == null) { 
    153154            //$args = func_get_args();var_dump($args); 
    154             throw new Exception("Unable to find a relation with the specified parameters"); 
     155 
     156            throw new ObjectNotFoundException("Unable to find a relation with the specified parameters"); 
    155157        } 
    156158        return new self($row); 
     
    159161    static public function getFromXml(Vocabulary $voc, DOMXPath $xpath, DOMNode $relationship) { 
    160162        $values = self::parseFromXml($relationship, $debug=false); 
    161         return self::getFromFullId($voc, $values['source_term_vocabulary_identifier'], $values['source_term_identifier'], $values['target_term_vocabulary_identifier'], $values['target_term_identifier'], $values['vdex_7_4_1_relationship_type_source'],  $values['vdex_7_4_2_relationship_type_value'], $values['vdex_7_1_identifier']); 
     163        $retval = self::getFromFullId($voc, $values['source_term_vocabulary_identifier'], $values['source_term_identifier'], $values['target_term_vocabulary_identifier'], $values['target_term_identifier'], $values['vdex_7_4_1_relationship_type_source'],  $values['vdex_7_4_2_relationship_type_value'], $values['vdex_7_1_identifier']); 
     164        return $retval; 
    162165    } 
    163166 
     
    516519    function import($data, $format, $document, $debug=false) 
    517520    { 
    518         if ($format == 'VDEX') 
    519         { 
     521        if ($format == 'VDEX') { 
     522 
    520523            $values = self::parseFromXml($data, $debug); 
     524 
    521525            $sql = "UPDATE vocabulary_relationships SET "; 
    522526            /* vdex_7_1_identifier */ 
     
    542546            $sql .= implode(', ', $sqlSetArray); 
    543547            $sql .= " WHERE  id={$this->mId}"; 
     548 
     549            //pretty_print_r($sql); 
     550 
     551 
     552            /* The following checks are necessary untill http://bugs.php.net/bug.php?id=52682 is fixed */ 
     553            try { 
     554                VocabularyTerm::getObject(array($source_term_identifier, $source_term_vocabulary_identifier)); 
     555                VocabularyTerm::getObject(array($target_term_identifier, $target_term_vocabulary_identifier)); 
     556                VocabularyTerm::getObject(array($vdex_7_4_2_relationship_type_value, $vdex_7_4_1_relationship_type_source)); 
     557            } 
     558            catch(MissingVocabularyTermException $e) { 
     559                throw new ImportException($e->getMessage()); 
     560            } 
    544561            $this->mBd->execSqlUpdate($sql, false); 
    545562        } 
    546         else 
    547         { 
    548             echo "<h1>VocabularyRelation::import(): Erreur:  Le format '$format' n'est pas supporté</h1>"; 
     563        else { 
     564            throw new ImportException("VocabularyRelation::import(): Erreur:  Le format '$format' n'est pas supporté"); 
    549565        } 
    550566    } 
  • html/classes/VocabularyTerm.php

    raafb30d rf4e524f  
    11661166 
    11671167    /** Fonction d'importation d'un terme dans un vocabulaire 
    1168      *  @param $data : the dom node 
     1168     *  @param $data Object the dom node 
    11691169     @param $format VDEX 
    11701170     @param $document DOMDocument where the node comes from 
  • html/classes/exceptions/MissingVocabularyException.php

    r3550449 rf4e524f  
    2323 * @author Copyright (C) 2005 François Proulx, Technologies Coeus inc. 
    2424*/ 
     25require_once("ObjectNotFoundException.php"); 
    2526 
    26 class MissingVocabularyException extends Exception 
     27class MissingVocabularyException extends ObjectNotFoundException 
    2728{ 
    2829    public function __construct($message = "", $code = 0)  
  • html/classes/exceptions/MissingVocabularyTermException.php

    r3550449 rf4e524f  
    2323 * @author Copyright (C) 2005 François Proulx, Technologies Coeus inc. 
    2424*/ 
     25require_once("ObjectNotFoundException.php"); 
    2526 
    26 class MissingVocabularyTermException extends Exception 
     27class MissingVocabularyTermException extends ObjectNotFoundException 
    2728{ 
    2829    public function __construct($message = "", $code = 0)  
  • html/classes/exceptions/NoTaxonPathException.php

    r3550449 rf4e524f  
    2323 * @author Copyright (C) 2005 François Proulx, Technologies Coeus inc. 
    2424*/ 
     25require_once("ObjectNotFoundException.php"); 
    2526 
    26 class NoTaxonPathException extends Exception 
     27class NoTaxonPathException extends ObjectNotFoundException 
    2728{ 
    2829        public function __construct($message=null, $code=null)  
Note: See TracChangeset for help on using the changeset viewer.