|
@@ -50,7 +50,8 @@ function ManageAttachments()
|
|
|
'moveAvatars' => 'MoveAvatars',
|
|
|
'repair' => 'RepairAttachments',
|
|
|
'remove' => 'RemoveAttachment',
|
|
|
- 'removeall' => 'RemoveAllAttachments'
|
|
|
+ 'removeall' => 'RemoveAllAttachments',
|
|
|
+ 'transfer' => 'TransferAttachments',
|
|
|
);
|
|
|
|
|
|
call_integration_hook('integrate_manage_attachments', array(&$subActions));
|
|
@@ -687,6 +688,7 @@ function MaintainFiles()
|
|
|
);
|
|
|
list ($context['num_attachments']) = $smcFunc['db_fetch_row']($request);
|
|
|
$smcFunc['db_free_result']($request);
|
|
|
+ $context['num_attachments'] = comma_format($context['num_attachments'], 0);
|
|
|
|
|
|
// Also get the avatar amount....
|
|
|
$request = $smcFunc['db_query']('', '
|
|
@@ -699,26 +701,53 @@ function MaintainFiles()
|
|
|
);
|
|
|
list ($context['num_avatars']) = $smcFunc['db_fetch_row']($request);
|
|
|
$smcFunc['db_free_result']($request);
|
|
|
+ $context['num_avatars'] = comma_format($context['num_avatars'], 0);
|
|
|
|
|
|
// Check the size of all the directories.
|
|
|
$request = $smcFunc['db_query']('', '
|
|
|
SELECT SUM(size)
|
|
|
- FROM {db_prefix}attachments',
|
|
|
+ FROM {db_prefix}attachments
|
|
|
+ WHERE attachment_type != {int:type}',
|
|
|
array(
|
|
|
+ 'type' => 1,
|
|
|
)
|
|
|
);
|
|
|
list ($attachmentDirSize) = $smcFunc['db_fetch_row']($request);
|
|
|
$smcFunc['db_free_result']($request);
|
|
|
-
|
|
|
- // Divide it into kilobytes.
|
|
|
$attachmentDirSize /= 1024;
|
|
|
+ $context['attachment_total_size'] = comma_format($attachmentDirSize, 2);
|
|
|
|
|
|
- // If they specified a limit only....
|
|
|
- if (!empty($modSettings['attachmentDirSizeLimit']))
|
|
|
- $context['attachment_space'] = max(round($modSettings['attachmentDirSizeLimit'] - $attachmentDirSize, 2), 0);
|
|
|
- $context['attachment_total_size'] = round($attachmentDirSize, 2);
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT COUNT(*), SUM(size)
|
|
|
+ FROM {db_prefix}attachments
|
|
|
+ WHERE id_folder = {int:folder_id}
|
|
|
+ AND attachment_type != {int:type}',
|
|
|
+ array(
|
|
|
+ 'folder_id' => $modSettings['currentAttachmentUploadDir'],
|
|
|
+ 'type' => 1,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ list ($current_dir_files, $current_dir_size) = $smcFunc['db_fetch_row']($request);
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+ $current_dir_size /= 1024;
|
|
|
|
|
|
- $context['attach_multiple_dirs'] = !empty($modSettings['currentAttachmentUploadDir']);
|
|
|
+ if (!empty($modSettings['attachmentDirSizeLimit']))
|
|
|
+ $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2);
|
|
|
+ $context['attachment_current_size'] = comma_format($current_dir_size, 2);
|
|
|
+
|
|
|
+ if (!empty($modSettings['attachmentDirFileLimit']))
|
|
|
+ $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0);
|
|
|
+ $context['attachment_current_files'] = comma_format($current_dir_files, 0);
|
|
|
+
|
|
|
+ $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false;
|
|
|
+ $context['attach_dirs'] = $attach_dirs;
|
|
|
+ $context['base_dirs'] = !empty($modSettings['attachment_basedirectories']) ? unserialize($modSettings['attachment_basedirectories']) : array();
|
|
|
+ $context['checked'] = isset($_SESSION['checked']) ? $_SESSION['checked'] : true;
|
|
|
+ if (!empty($_SESSION['results']))
|
|
|
+ {
|
|
|
+ $context['results'] = $_SESSION['results'];
|
|
|
+ unset($_SESSION['results']);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1881,6 +1910,7 @@ function ManageAttachmentPaths()
|
|
|
$new_dirs = array();
|
|
|
foreach ($_POST['dirs'] as $id => $path)
|
|
|
{
|
|
|
+ $error = '';
|
|
|
$id = (int) $id;
|
|
|
if ($id < 1)
|
|
|
continue;
|
|
@@ -1984,11 +2014,11 @@ function ManageAttachmentPaths()
|
|
|
unlink($path . '/.htaccess');
|
|
|
unlink($path . '/index.php');
|
|
|
if (!@rmdir($path))
|
|
|
- $errors[] = $path . ': ' . $txt['attach_dir_no_delete'];
|
|
|
+ $error = $path . ': ' . $txt['attach_dir_no_delete'];
|
|
|
}
|
|
|
|
|
|
// Remove it from the base directory list.
|
|
|
- if (empty($errors) && !empty($modSettings['attachment_basedirectories']))
|
|
|
+ if (empty($error) && !empty($modSettings['attachment_basedirectories']))
|
|
|
{
|
|
|
unset($modSettings['attachment_basedirectories'][$id]);
|
|
|
updateSettings(array('attachment_basedirectories' => serialize($modSettings['attachment_basedirectories'])));
|
|
@@ -1996,10 +2026,12 @@ function ManageAttachmentPaths()
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
- $errors[] = $path . ': ' . $txt['attach_dir_no_remove'];
|
|
|
+ $error = $path . ': ' . $txt['attach_dir_no_remove'];
|
|
|
|
|
|
- if (empty($errors))
|
|
|
+ if (empty($error))
|
|
|
continue;
|
|
|
+ else
|
|
|
+ $errors[] = $error;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2044,7 +2076,7 @@ function ManageAttachmentPaths()
|
|
|
$bid = 0;
|
|
|
}
|
|
|
|
|
|
- If ($bid >= 0)
|
|
|
+ if ($bid >= 0 && isset($modSettings['basedirectory_for_attachments']))
|
|
|
{
|
|
|
$modSettings['last_attachments_directory'][$bid] = (int) $num;
|
|
|
updateSettings(array(
|
|
@@ -2053,6 +2085,13 @@ function ManageAttachmentPaths()
|
|
|
'use_subdirectories_for_attachments' => $use_subdirectories_for_attachments,
|
|
|
));
|
|
|
}
|
|
|
+ elseif ($bid == 0)
|
|
|
+ {
|
|
|
+ $modSettings['last_attachments_directory'][$bid] = (int) $num;
|
|
|
+ updateSettings(array(
|
|
|
+ 'last_attachments_directory' => serialize($modSettings['last_attachments_directory']),
|
|
|
+ ));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2529,4 +2568,219 @@ function attachDirStatus($dir, $expected_files)
|
|
|
return array('ok', false, $num_files);
|
|
|
}
|
|
|
|
|
|
+function TransferAttachments()
|
|
|
+{
|
|
|
+ global $modSettings, $context, $smcFunc, $sourcedir, $txt, $boarddir;
|
|
|
+
|
|
|
+ checkSession();
|
|
|
+
|
|
|
+ $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
|
|
|
+ if (!empty($modSettings['attachment_basedirectories']))
|
|
|
+ $modSettings['attachment_basedirectories'] = unserialize($modSettings['attachment_basedirectories']);
|
|
|
+ else
|
|
|
+ $modSettings['basedirectory_for_attachments'] = array();
|
|
|
+
|
|
|
+ $_POST['from'] = (int) $_POST['from'];
|
|
|
+ $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0;
|
|
|
+ $_POST['to'] = (int) $_POST['to'];
|
|
|
+ $start = !empty($_POST['empty_it']) ? 0 : $modSettings['attachmentDirFileLimit'];
|
|
|
+ $_SESSION['checked'] = !empty($_POST['empty_it']) ? true : false;
|
|
|
+ $limit = 500;
|
|
|
+ $results = '';
|
|
|
+ $dir_files = 0;
|
|
|
+ $current_progress = 0;
|
|
|
+ $total_moved = 0;
|
|
|
+ $total_not_moved = 0;
|
|
|
+
|
|
|
+ if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to'])))
|
|
|
+ $results .= $txt['attachment_transfer_no_dir'] . '<br />';
|
|
|
+
|
|
|
+ if ($_POST['from'] == $_POST['to'])
|
|
|
+ $results .= $txt['attachment_transfer_same_dir'] . '<br />';
|
|
|
+
|
|
|
+ if (empty($results))
|
|
|
+ {
|
|
|
+ // Get the total file count for the progess bar.
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT COUNT(*)
|
|
|
+ FROM {db_prefix}attachments
|
|
|
+ WHERE id_folder = {int:folder_id}
|
|
|
+ AND attachment_type != {int:attachment_type}',
|
|
|
+ array(
|
|
|
+ 'folder_id' => $_POST['from'],
|
|
|
+ 'attachment_type' => 1,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ list ($total_progress) = $smcFunc['db_fetch_row']($request);
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+ $total_progress -= $start;
|
|
|
+
|
|
|
+ if ($total_progress < 1)
|
|
|
+ $results .= $txt['attachment_transfer_no_find'] . '<br />';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($results))
|
|
|
+ {
|
|
|
+ // Where are they going?
|
|
|
+ if (!empty($_POST['auto']))
|
|
|
+ {
|
|
|
+ require_once($sourcedir . '/Attachments.php');
|
|
|
+
|
|
|
+ $modSettings['automanage_attachments'] = 1;
|
|
|
+ $modSettings['use_subdirectories_for_attachments'] = $_POST['auto'] == -1 ? 0 : 1;
|
|
|
+ $modSettings['basedirectory_for_attachments'] = $_POST['auto'] > 0 ? $modSettings['attachmentUploadDir'][$_POST['auto']] : $modSettings['basedirectory_for_attachments'];
|
|
|
+
|
|
|
+ automanage_attachments_check_directory();
|
|
|
+ $new_dir = $modSettings['currentAttachmentUploadDir'];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ $new_dir = $_POST['to'];
|
|
|
+
|
|
|
+ $modSettings['currentAttachmentUploadDir'] = $new_dir;
|
|
|
+
|
|
|
+ $break = false;
|
|
|
+ while ($break == false)
|
|
|
+ {
|
|
|
+ @set_time_limit(300);
|
|
|
+ if (function_exists('apache_reset_timeout'))
|
|
|
+ @apache_reset_timeout();
|
|
|
+
|
|
|
+ // If limts are set, get the file count and size for the destination folder
|
|
|
+ if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit'])))
|
|
|
+ {
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT COUNT(*), SUM(size)
|
|
|
+ FROM {db_prefix}attachments
|
|
|
+ WHERE id_folder = {int:folder_id}
|
|
|
+ AND attachment_type != {int:attachment_type}',
|
|
|
+ array(
|
|
|
+ 'folder_id' => $new_dir,
|
|
|
+ 'attachment_type' => 1,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ list ($dir_files, $dir_size) = $smcFunc['db_fetch_row']($request);
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Find some attachments to move
|
|
|
+ $request = $smcFunc['db_query']('', '
|
|
|
+ SELECT id_attach, filename, id_folder, file_hash, size
|
|
|
+ FROM {db_prefix}attachments
|
|
|
+ WHERE id_folder = {int:folder}
|
|
|
+ AND attachment_type != {int:attachment_type}
|
|
|
+ LIMIT {int:start}, {int:limit}',
|
|
|
+ array(
|
|
|
+ 'folder' => $_POST['from'],
|
|
|
+ 'attachment_type' => 1,
|
|
|
+ 'start' => $start,
|
|
|
+ 'limit' => $limit,
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($smcFunc['db_num_rows']($request) === 0)
|
|
|
+ {
|
|
|
+ if (empty($current_progress))
|
|
|
+ $results .= $txt['attachment_transfer_no_find'] . '<br />';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($smcFunc['db_num_rows']($request) < $limit)
|
|
|
+ $break = true;
|
|
|
+
|
|
|
+ // Move them
|
|
|
+ $moved = array();
|
|
|
+ while ($row = $smcFunc['db_fetch_assoc']($request))
|
|
|
+ {
|
|
|
+ $source = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
|
|
|
+ $dest = $modSettings['attachmentUploadDir'][$new_dir] . '/' . basename($source);
|
|
|
+
|
|
|
+ if (@rename($source, $dest))
|
|
|
+ {
|
|
|
+ $total_moved++;
|
|
|
+ $current_progress++;
|
|
|
+ $moved[] = $row['id_attach'];
|
|
|
+
|
|
|
+ // Size and file count check
|
|
|
+ if (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))
|
|
|
+ {
|
|
|
+ $dir_files++;
|
|
|
+ $dir_size += !empty($row['size']) ? $row['size'] : filesize($source);
|
|
|
+
|
|
|
+ // If we've reached a limit. Do something.
|
|
|
+ if (!empty($modSettings['attachmentDirSizeLimit']) && $dir_size > $modSettings['attachmentDirSizeLimit'] * 1024 || (!empty($modSettings['attachmentDirFileLimit']) && $dir_files > $modSettings['attachmentDirFileLimit'] - 1))
|
|
|
+ {
|
|
|
+ if (!empty($_POST['auto']))
|
|
|
+ {
|
|
|
+ // Since we're in auto mode. Create a new folder and reset the counters.
|
|
|
+ automanage_attachments_by_space();
|
|
|
+
|
|
|
+ $results .= sprintf($txt['attachments_transfered'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]) . '<br />';
|
|
|
+ if (!empty($total_not_moved))
|
|
|
+ $results .= sprintf($txt['attachments_not_transfered'], $total_not_moved) . '<br />';
|
|
|
+
|
|
|
+ $dir_files = -1;
|
|
|
+ $total_moved = 0;
|
|
|
+ $total_not_moved = 0;
|
|
|
+
|
|
|
+ $break = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Hmm, time to bail out then...
|
|
|
+ $results .= $txt['attachment_transfer_no_room'] . '<br />';
|
|
|
+ $break = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ $total_not_moved++;
|
|
|
+ }
|
|
|
+ $smcFunc['db_free_result']($request);
|
|
|
+
|
|
|
+ // Update the database
|
|
|
+ $smcFunc['db_query']('', '
|
|
|
+ UPDATE {db_prefix}attachments
|
|
|
+ SET id_folder = {int:new}
|
|
|
+ WHERE id_attach IN ({array_int:attachments})',
|
|
|
+ array(
|
|
|
+ 'attachments' => $moved,
|
|
|
+ 'new' => $new_dir,
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $moved = array();
|
|
|
+ $new_dir = $modSettings['currentAttachmentUploadDir'];
|
|
|
+
|
|
|
+ // Create the progress bar.
|
|
|
+ if (!$break)
|
|
|
+ {
|
|
|
+ $percent_done = min(round($current_progress / $total_progress * 100, 0), 100);
|
|
|
+ $prog_bar = '
|
|
|
+ <div class="progress_bar">
|
|
|
+ <div class="full_bar">' . $percent_done . '%</div>
|
|
|
+ <div class="green_percent" style="width: ' . $percent_done . '%;"> </div>
|
|
|
+ </div>';
|
|
|
+ // Write it to a file so it can be displayed
|
|
|
+ $fp = fopen($boarddir . '/progress.php', "w");
|
|
|
+ fwrite($fp, $prog_bar);
|
|
|
+ fclose($fp);
|
|
|
+ usleep(500000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $results .= sprintf($txt['attachments_transfered'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]) . '<br />';
|
|
|
+ if (!empty($total_not_moved))
|
|
|
+ $results .= sprintf($txt['attachments_not_transfered'], $total_not_moved) . '<br />';
|
|
|
+ }
|
|
|
+
|
|
|
+ $_SESSION['results'] = $results;
|
|
|
+ if (file_exists($boarddir . '/progress.php'))
|
|
|
+ unlink($boarddir . '/progress.php');
|
|
|
+
|
|
|
+ redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer');
|
|
|
+}
|
|
|
+
|
|
|
?>
|