Ignore:
Timestamp:
Mar 18, 2010, 11:47:11 PM (14 years ago)
Author:
grum
Message:

database is partially filled during the install process, and fill database picture per picture each time a page is displayed (and until all the database is filled)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AMetaData/amd_aip.class.inc.php

    r5097 r5183  
    3333  protected $tabsheet;
    3434  protected $ajax;
    35   protected $jpegMD;
    3635
    3736  /**
     
    4241   * @param String $filelocation
    4342   */
    44   function __construct($prefixeTable, $filelocation)
     43  public function __construct($prefixeTable, $filelocation)
    4544  {
    4645    parent::__construct($prefixeTable, $filelocation);
     
    5756                          $this->page_link.'&fAMD_tabsheet=help');
    5857    $this->ajax = new Ajax();
    59     $this->jpegMD=new JpegMetaData();
    60   }
    61 
    62   function __destruct()
     58  }
     59
     60  public function __destruct()
    6361  {
    6462    unset($this->tabsheet);
    6563    unset($this->ajax);
    66     unset($this->jpegMD);
     64    parent::__destruct();
    6765  }
    6866
     
    681679
    682680
    683   /**
    684    * this function analyze tags from a picture, and insert the result into the
    685    * database
    686    *
    687    * NOTE : only implemented tags are analyzed and stored
    688    *
    689    * @param String $fileName : filename of picture to analyze
    690    * @param Integer $imageId : id of image in piwigo's database
    691    */
    692   protected function analyzeImageFile($fileName, $imageId)
    693   {
    694     /*
    695      * the JpegMetaData object is instancied in the constructor
    696      */
    697     $this->jpegMD->load($fileName, Array(
    698       'filter' => JpegMetaData::TAGFILTER_IMPLEMENTED,
    699       'optimizeIptcDateTime' => true)
    700     );
    701 
    702     $sqlInsert="";
    703     $massInsert=array();
    704     $nbTags=0;
    705     foreach($this->jpegMD->getTags() as $key => $val)
    706     {
    707       $value=$val->getLabel();
    708 
    709       if($val->isTranslatable())
    710         $translatable="y";
    711       else
    712         $translatable="n";
    713 
    714       if($value instanceof DateTime)
    715       {
    716         $value=$value->format("Y-m-d H:i:s");
    717       }
    718       elseif(is_array($value))
    719       {
    720         /*
    721          * array values are stored in a serialized string
    722          */
    723         $value=serialize($value);
    724       }
    725 
    726       $sql="SELECT numId FROM ".$this->tables['used_tags']." WHERE tagId = '$key'";
    727       $result=pwg_query($sql);
    728       if($result)
    729       {
    730         $numId=-1;
    731         while($row=mysql_fetch_assoc($result))
    732         {
    733           $numId=$row['numId'];
    734         }
    735 
    736         if($numId>0)
    737         {
    738           $nbTags++;
    739           if($sqlInsert!="") $sqlInsert.=", ";
    740           $sqlInsert.="($imageId, '$numId', '".addslashes($value)."')";
    741           $massInsert[]="('$imageId', '$numId', '".addslashes($value)."') ";
    742         }
    743       }
    744     }
    745 
    746     $sql="REPLACE INTO ".$this->tables['images_tags']." (imageId, numId, value)
    747           VALUES ".implode(", ", $massInsert);
    748     pwg_query($sql);
    749     //mass_inserts($this->tables['images_tags'], array('imageId', 'numId', 'value'), $massInsert);
    750 
    751     $sql="UPDATE ".$this->tables['images']."
    752             SET analyzed = 'y', nbTags=".$nbTags."
    753             WHERE imageId=$imageId;";
    754     pwg_query($sql);
    755 
    756 
    757     return("$imageId=$nbTags;");
    758   }
    759 
    760 
    761   /**
    762    * returns the number of pictures analyzed
    763    *
    764    * @return Integer
    765    */
    766   protected function getNumOfPictures()
    767   {
    768     $numOfPictures=0;
    769     $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
    770             WHERE analyzed='y';";
    771     $result=pwg_query($sql);
    772     if($result)
    773     {
    774       while($row=mysql_fetch_row($result))
    775       {
    776         $numOfPictures=$row[0];
    777       }
    778     }
    779     return($numOfPictures);
    780   }
    781681
    782682
     
    910810  private function ajax_amd_makeStatsConsolidation()
    911811  {
    912     $sql="UPDATE ".$this->tables['used_tags']." ut,
    913             (SELECT COUNT(imageId) AS nb, numId
    914               FROM ".$this->tables['images_tags']."
    915               GROUP BY numId) nb
    916           SET ut.numOfImg = nb.nb
    917           WHERE ut.numId = nb.numId;";
    918     pwg_query($sql);
     812    $this->makeStatsConsolidation();
    919813  }
    920814
Note: See TracChangeset for help on using the changeset viewer.