Index: trunk/kernel/units/general/inp_temp_handler.php =================================================================== diff -u -N --- trunk/kernel/units/general/inp_temp_handler.php (revision 2604) +++ trunk/kernel/units/general/inp_temp_handler.php (revision 0) @@ -1,158 +0,0 @@ -GetTempName($table), - $table, - $IdField, - $ids); - $this->Conn->Query($query); - if (isset($autoincrement) && !empty($autoincrement)) { - $query = sprintf("ALTER TABLE %s - CHANGE %s %s INT(11) NOT NULL AUTO_INCREMENT, - ADD PRIMARY KEY (%s)", - $this->GetTempName($table), - $autoincrement, - $autoincrement, - $autoincrement, - $this->GetTempName($table)); - echo $query.'
'; - $this->Conn->Query($query); - } - - if($table == TABLE_PREFIX.'Images') - { - $query = sprintf('SELECT LocalPath,ThumbPath FROM %s WHERE %s IN (%s)',$table,$IdField,$ids); - $res = $this->Conn->Query($query); - - foreach ($res as $record) - { - foreach ($record as $field => $field_value) - { - $source_file = FULL_PATH.$field_value; - $dest_file = FULL_PATH.str_replace(IMAGES_PATH, IMAGES_PENDING_PATH, $field_value); - copy($source_file, $dest_file); - } - } - - $update_sql = 'UPDATE '.$this->GetTempName($table).' SET LocalPath = REPLACE(LocalPath, - "'.IMAGES_PATH.'", "'.IMAGES_PENDING_PATH.'"), - ThumbPath = REPLACE(ThumbPath, - "'.IMAGES_PATH.'","'.IMAGES_PENDING_PATH.'") - WHERE '.$IdField.' IN ('.$ids.')'; - $this->Conn->Query($update_sql); - - } - - } - - function CopyTempToOriginal($table, $IdField, $autoincrement=null) - { - if (isset($autoincrement) && !empty($autoincrement)) - { - $this->RemoveAutoincrement($table, $autoincrement); - } - - if( $table != $this->MasterTable ) - { - // get main ids - $sql = 'SELECT '.$this->Tables[$table]['ForeignKey']. - ' FROM '.$this->MasterTable. - ' WHERE '.$this->Tables[$this->MasterTable]['IdField'].' IN ('.implode(',',$this->MasterIDs).')'; - $main_ids = $this->Conn->GetCol($sql); - - if($main_ids) - { - if ($table == TABLE_PREFIX.'Images') - { - $sql = 'SELECT LocalPath, ThumbPath FROM '.$table. - ' WHERE '.$IdField.' IN ('.implode(',', $main_ids).')'; - $res = $this->Conn->Query($sql); - - foreach ($res as $record) - { - foreach ($record as $field => $field_value) - { - $source_file = FULL_PATH.$field_value; - unlink($source_file); - } - } - } - - // delete all related to main table records from subtable - $sql = 'DELETE FROM '.$table.' WHERE '.$IdField.' IN ('.implode(',',$main_ids).')'; - $this->Conn->Query($sql); - } - - $subtable_idfield = $this->Tables[$table]['SubIDField']; - $this->Conn->Query('UPDATE '.$this->GetTempName($table).' SET '.$subtable_idfield.' = 0 WHERE '.$subtable_idfield.' < 0'); - } - else - { - // get IDs, that exist in temp table - $query = sprintf('SELECT %s FROM %s', - $IdField, - $this->GetTempName($table)); - $this->MasterIDs = $this->Conn->GetCol($query); // were $temp_ids before - if($this->MasterIDs) - { - // delete original records from master table - $query = sprintf('DELETE FROM %s WHERE %s IN (%s)', - $table, - $IdField, - implode(',',$this->MasterIDs) ); - $this->Conn->Query($query); - } - } - - $query = sprintf("INSERT INTO %s - SELECT * FROM %s", - $table, - $this->GetTempName($table)); - $this->Conn->Query($query); - - - if($table == TABLE_PREFIX.'Images' && count($main_ids) > 0) - { - $query = sprintf(' SELECT LocalPath, ThumbPath FROM %s - WHERE %s IN (%s)', - $table, - $IdField, - implode(',',$this->MasterIDs)); - $res = $this->Conn->Query($query); - - foreach ($res as $record) - { - foreach ($record as $field => $field_value) - { - $source_file = FULL_PATH.$field_value; - $dest_file = FULL_PATH.str_replace(IMAGES_PENDING_PATH, IMAGES_PATH, $field_value); - rename($source_file, $dest_file); - } - } - - $update_sql = 'UPDATE '.$table.' SET LocalPath = REPLACE(LocalPath, - "'.IMAGES_PENDING_PATH.'", "'.IMAGES_PATH.'"), - ThumbPath = REPLACE(ThumbPath, - "'.IMAGES_PENDING_PATH.'", "'.IMAGES_PATH.'") - WHERE '.$IdField.' IN ('.implode(',', $this->MasterIDs).')'; - $this->Conn->Query($update_sql); - - } - - return $this->Conn->getInsertID(); - } - -} - - -?> \ No newline at end of file