Index: trunk/kernel/include/theme.php =================================================================== diff -u -r384 -r423 --- trunk/kernel/include/theme.php (.../theme.php) (revision 384) +++ trunk/kernel/include/theme.php (.../theme.php) (revision 423) @@ -290,44 +290,36 @@ return $f->LoadFileContents(); } - function FindMissingFiles($path, $where = null, $OrderBy = null, $limit = null) - { - global $objConfig, $pathchar, $pathtoroot, $ttt_time; - - $this->Clear(); - $fullpath = $pathtoroot."themes/".$path; - $this->LoadFiles($this->ThemeId, $where,$OrderBy,$limit); - - //assemble directoy file list - $files = filelist($fullpath, NULL, "tpl"); + function FindMissingFiles($path, $where = null, $OrderBy = null, $limit = null) + { + global $pathtoroot; + $this->Clear(); + $fullpath = $pathtoroot.'themes/'.$path; + // get all templates from database + $sql = 'SELECT FileId AS i,CONCAT(FilePath,"/",FileName) AS f FROM '.$this->SourceTable. ' WHERE ThemeId='.$this->ThemeId; + $DBfiles=Array(); + if($rs = $this->adodbConnection->Execute($sql)) + { + while(!$rs->EOF) + { + $DBfiles[$rs->fields['i']] = $fullpath.$rs->fields['f']; + $rs->MoveNext(); + } + $rs->Free(); + } + // get all templates file from disk + $HDDfiles = filelist($fullpath, NULL, "tpl"); - //assemble DB file list - $tt_inc=0; - $db_file_array=array(0 => '0'); - foreach($this->Items as $f) - { - $db_file_array[$tt_inc]=$f->Get("FilePath").$f->Get("FileName"); - $tt_inc++; - } - - //iterate through all files in the directory - for($i=0;$iAddFile($file_path,$file_base,$this->ThemeId,0,""); - } + $missingFiles=array_diff($HDDfiles,$DBfiles); + $orphanFiles=array_diff($DBfiles,$HDDfiles); + + $sql = 'DELETE FROM '.$this->SourceTable.' WHERE FileId IN('.join(',',array_keys($orphanFiles)).')'; + $this->adodbConnection->Execute($sql); - } - - } + $l=strlen($fullpath); + foreach($missingFiles as $file) + $this->AddFile(substr(dirname($file),$l),basename($file),$this->ThemeId,0,''); + } } RegisterPrefix("clsTheme","theme","kernel/include/theme.php");