Last active
September 26, 2015 06:10
-
-
Save daohoangson/68ebee3665b0d157d859 to your computer and use it in GitHub Desktop.
internal_data file check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (empty($argv[1])) { | |
die("\$argv[1] (\$backUpDir) is missing!\n"); | |
} | |
$backUpDir = rtrim($argv[1], '/'); | |
if (!is_dir($backUpDir)) { | |
die("{$backUpDir} is not a directory."); | |
} | |
$position = 0; | |
$limit = 100; | |
if (!empty($argv[2])) { | |
$argv2 = array(); | |
parse_str($argv[2], $argv2); | |
if (isset($argv2['position'])) $position = intval($argv2['position']); | |
if (isset($argv2['limit'])) $limit = intval($argv2['limit']); | |
} | |
$startTime = microtime(true); | |
$fileDir = getcwd(); | |
require($fileDir . '/library/XenForo/Autoloader.php'); | |
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library'); | |
XenForo_Application::initialize($fileDir . '/library', $fileDir); | |
XenForo_Application::set('page_start_time', $startTime); | |
$fc = new XenForo_FrontController(new XenForo_Dependencies_Public()); | |
$db = XenForo_Application::getDb(); | |
$total = $db->fetchOne('SELECT COUNT(*) FROM `xf_attachment_data`'); | |
echo("Total: {$total}\n"); | |
$defaultCount = $db->fetchOne('SELECT COUNT(*) FROM `xf_attachment_data` WHERE bdattachmentstore_engine IS NULL OR bdattachmentstore_engine = ""'); | |
echo("Default Count: {$defaultCount}\n"); | |
/** @var XenForo_Model_Attachment $attachmentModel */ | |
$attachmentModel = XenForo_Model::create('XenForo_Model_Attachment'); | |
try { | |
$i = 0; | |
while(true) { | |
$rows = $db->fetchAll('SELECT * FROM `xf_attachment_data` WHERE data_id > ? ORDER BY data_id LIMIT ?', array($position, $limit)); | |
if (empty($rows)) { | |
break; // while(true) | |
} | |
foreach ($rows as $data) { | |
$position = $data['data_id']; | |
$i++; | |
if ($i % 1000 == 0) { | |
echo("...{$position}"); | |
} | |
if (!empty($data['bdattachmentstore_engine'])) { | |
continue; | |
} | |
$path = $attachmentModel->getAttachmentDataFilePath($data); | |
if (!file_exists($path)) { | |
$backUpPath = preg_replace('#^' . preg_quote( | |
rtrim(XenForo_Helper_File::getInternalDataPath(), '/'), '#') . '#', $backUpDir, $path); | |
if (file_exists($backUpPath)) { | |
XenForo_Helper_File::createDirectory(dirname($path)); | |
copy($backUpPath, $path); | |
echo(" copied `{$data['data_id']}`"); | |
} else { | |
echo(" !found `{$path}`\n"); | |
} | |
} | |
} | |
} | |
} catch (Exception $e) { | |
die($e->getMessage()); | |
} | |
die("Done\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment