static function CheckChangedFiles($sync_data) { $sync_id3 = !WPFB_Core::$settings->disable_id3; $upload_dir = self::cleanPath(WPFB_Core::UploadDir()); foreach ($sync_data->files as $id => $file) { $file_path = self::cleanPath($file->GetLocalPath(true)); $sync_data->known_filenames[] = substr($file_path, strlen($upload_dir)); if ($file->GetThumbPath()) { $sync_data->known_filenames[] = substr(self::cleanPath($file->GetThumbPath()), strlen($upload_dir)); } if ($file->file_category > 0 && is_null($file->GetParent())) { $sync_data->log['warnings'][] = sprintf(__('Category (ID %d) of file %s does not exist!', WPFB), $file->file_category, $file->GetLocalPathRel()); } // remove thumb if missing if ($file->file_thumbnail && !file_exists($file->GetThumbPath())) { $file->file_thumbnail = ''; $file->DBSave(); $sync_data->log['changed'][$id] = $file; } // TODO: check for file changes remotly if ($file->IsRemote()) { continue; } if (!@is_file($file_path) || !@is_readable($file_path)) { $sync_data->missing_files[$id] = $file; continue; } if ($sync_data->hash_sync) { $file_hash = WPFB_Admin::GetFileHash($file_path); } $file_size = WPFB_FileUtils::GetFileSize($file_path); $file_mtime = filemtime($file_path); $file_analyzetime = !$sync_id3 ? $file_mtime : WPFB_GetID3::GetFileAnalyzeTime($file); if (is_null($file_analyzetime)) { $file_analyzetime = 0; } if ($sync_data->hash_sync && $file->file_hash != $file_hash || $file->file_size != $file_size || $file->file_mtime != $file_mtime || $file_analyzetime < $file_mtime) { $file->file_size = $file_size; $file->file_mtime = $file_mtime; $file->file_hash = $sync_data->hash_sync ? $file_hash : WPFB_Admin::GetFileHash($file_path); WPFB_GetID3::UpdateCachedFileInfo($file); $res = $file->DBSave(); if (!empty($res['error'])) { $sync_data->log['error'][$id] = $file; } else { $sync_data->log['changed'][$id] = $file; } } } // prepare for binary search (fast_in_array) sort($sync_data->known_filenames); }
/** * * @param WPFB_SyncData $sync_data * @param boolean $output */ private static function CheckChangedFiles($sync_data, $output) { if ($output) { self::DEcho('<p>' . sprintf(__('Checking %d files for changes...', 'wp-filebase'), count($sync_data->files)) . ' '); } $sync_id3 = !WPFB_Core::$settings->disable_id3; $upload_dir = self::cleanPath(WPFB_Core::UploadDir()); if (count($sync_data->files) > 0) { wpfb_loadclass('ProgressReporter'); $progress_reporter = new WPFB_ProgressReporter(); $progress_reporter->InitProgress(count($sync_data->files)); $progress_reporter->InitProgressField('Current File: %#%', '-', true); } $i = 0; foreach ($sync_data->files as $id => $file) { $file_path = self::cleanPath($file->GetLocalPath(true)); $rel_file_path = substr($file_path, strlen($upload_dir)); $progress_reporter->SetProgress(++$i); $progress_reporter->SetField($rel_file_path); $sync_data->known_filenames[] = $rel_file_path; if ($file->GetThumbPath()) { $sync_data->known_filenames[] = substr(self::cleanPath($file->GetThumbPath()), strlen($upload_dir)); } if ($file->file_category > 0 && is_null($file->GetParent())) { $sync_data->log['warnings'][] = sprintf(__('Category (ID %d) of file %s does not exist!', 'wp-filebase'), $file->file_category, $file->GetLocalPathRel()); } // remove thumb if missing if ($file->file_thumbnail && !file_exists($file->GetThumbPath())) { $file->file_thumbnail = ''; $file->DBSave(); $sync_data->log['changed'][$id] = $file; } // TODO: check for file changes remotly if ($file->IsRemote()) { continue; } if (!@is_file($file_path) || !@is_readable($file_path)) { $sync_data->missing_files[$id] = $file; continue; } if ($sync_data->hash_sync) { $file_hash = WPFB_Admin::GetFileHash($file_path); } $file_size = WPFB_FileUtils::GetFileSize($file_path); $file_mtime = filemtime($file_path); $file_analyzetime = !$sync_id3 ? $file_mtime : WPFB_GetID3::GetFileAnalyzeTime($file); if (is_null($file_analyzetime)) { $file_analyzetime = 0; } if ($sync_data->hash_sync && $file->file_hash != $file_hash || $file->file_size != $file_size || $file->file_mtime != $file_mtime || $file_analyzetime < $file_mtime) { $file->file_size = $file_size; $file->file_mtime = $file_mtime; $file->file_hash = $sync_data->hash_sync ? $file_hash : WPFB_Admin::GetFileHash($file_path); WPFB_Sync::ScanFile($file); // this can be async! $res = $file->DBSave(); if (!empty($res['error'])) { $sync_data->log['error'][$id] = $res['error'] . " (file {$rel_file_path})"; } else { $sync_data->log['changed'][$id] = $file; } } } // prepare for binary search (fast_in_array) sort($sync_data->known_filenames); if ($output) { self::DEcho('- done!</p>'); } }