mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Move all CLI scripts except common.cron to the "scripts" directory under the corresponding module
This commit is contained in:
parent
792ea89e64
commit
9ca2f79dce
14 changed files with 490 additions and 394 deletions
61
modules/file/scripts/cleanEmptyDirs.php
Normal file
61
modules/file/scripts/cleanEmptyDirs.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This script deletes empty directories under the 'files' directory.
|
||||
*
|
||||
* It may be useful when your web host imposes a hard limit on the number of
|
||||
* inodes, or when your backups take too long due to the large number of
|
||||
* unused directories.
|
||||
*
|
||||
* This script only works on Unix-like operating systems where the 'find'
|
||||
* command is available.
|
||||
*/
|
||||
if (!defined('RX_VERSION'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialize the exit status.
|
||||
$exit_status = 0;
|
||||
|
||||
// Delete empty directories in the attachment directory.
|
||||
passthru(sprintf('find %s -type d -empty -delete', escapeshellarg(RX_BASEDIR . 'files/attach')), $result);
|
||||
if ($result == 0)
|
||||
{
|
||||
echo "Successfully deleted all empty directories under files/attach.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while deleting empty directories under files/attach.\n";
|
||||
$exit_status = $result;
|
||||
}
|
||||
|
||||
// Delete empty directories in the member extra info directory.
|
||||
passthru(sprintf('find %s -type d -empty -delete', escapeshellarg(RX_BASEDIR . 'files/member_extra_info')), $result);
|
||||
if ($result == 0)
|
||||
{
|
||||
echo "Successfully deleted all empty directories under files/member_extra_info.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while deleting empty directories under files/member_extra_info.\n";
|
||||
$exit_status = $result;
|
||||
}
|
||||
|
||||
// Delete empty directories in the thumbnails directory.
|
||||
passthru(sprintf('find %s -type d -empty -delete', escapeshellarg(RX_BASEDIR . 'files/thumbnails')), $result);
|
||||
if ($result == 0)
|
||||
{
|
||||
echo "Successfully deleted all empty directories under files/thumbnails.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while deleting empty directories under files/thumbnails.\n";
|
||||
$exit_status = $result;
|
||||
}
|
||||
|
||||
// Set the exit status if there were any errors.
|
||||
if ($exit_status != 0)
|
||||
{
|
||||
exit($exit_status);
|
||||
}
|
||||
102
modules/file/scripts/cleanGarbageFiles.php
Normal file
102
modules/file/scripts/cleanGarbageFiles.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This script deletes files that were not properly uploaded.
|
||||
*
|
||||
* Files can remain in an invalid status for two reasons: 1) a user abandons
|
||||
* a document or comment after uploading files; or 2) a chunked upload is
|
||||
* aborted without the server having any opportunity to clean it up.
|
||||
* These files can obviously take up a lot of disk space. In order to prevent
|
||||
* them from accumulating too much, you should run this script at least once
|
||||
* every few days.
|
||||
*/
|
||||
if (!defined('RX_VERSION'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialize the exit status.
|
||||
$exit_status = 0;
|
||||
|
||||
// Delete garbage files older than this number of days.
|
||||
$days = intval($args[0] ?? 0) ?: 10;
|
||||
|
||||
// Initialize objects.
|
||||
$oDB = DB::getInstance();
|
||||
$oFileController = FileController::getInstance();
|
||||
|
||||
// Find and delete files where isvalid = N.
|
||||
while (true)
|
||||
{
|
||||
$output = executeQueryArray('file.getFileList', [
|
||||
'isvalid' => 'N',
|
||||
'list_count' => 50,
|
||||
'regdate_before' => date('YmdHis', time() - ($days * 86400)),
|
||||
]);
|
||||
|
||||
if ($output->toBool())
|
||||
{
|
||||
if ($output->data)
|
||||
{
|
||||
$oDB->begin();
|
||||
foreach ($output->data as $file_info)
|
||||
{
|
||||
$oFileController->deleteFile($file_info->file_srl);
|
||||
}
|
||||
$oDB->commit();
|
||||
|
||||
if ($output->page_navigation && $output->page_navigation->total_count == count($output->data))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while deleting garbage files older than $days days.\n";
|
||||
echo $output->getMessage() . "\n";
|
||||
$exit_status = 11;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($exit_status == 0)
|
||||
{
|
||||
echo "Successfully deleted all garbage files older than $days days.\n";
|
||||
}
|
||||
|
||||
// Find and delete temporary chunks.
|
||||
$dirname = RX_BASEDIR . 'files/attach/chunks';
|
||||
$threshold = time() - ($days * 86400);
|
||||
$chunks = Rhymix\Framework\Storage::readDirectory($dirname);
|
||||
if ($chunks)
|
||||
{
|
||||
foreach ($chunks as $chunk)
|
||||
{
|
||||
if (@filemtime($chunk) < $threshold)
|
||||
{
|
||||
$result = Rhymix\Framework\Storage::delete($chunk);
|
||||
if (!$result)
|
||||
{
|
||||
$exit_status = 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($exit_status == 0)
|
||||
{
|
||||
echo "Successfully deleted temporary file chunks older than $days days.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while deleting temporary file chunks older than $days days.\n";
|
||||
}
|
||||
|
||||
// Set the exit status if there were any errors.
|
||||
if ($exit_status != 0)
|
||||
{
|
||||
exit($exit_status);
|
||||
}
|
||||
44
modules/file/scripts/cleanThumbnails.php
Normal file
44
modules/file/scripts/cleanThumbnails.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This script deletes old thumbnails.
|
||||
*
|
||||
* Thumbnails can take up a large amount of disk space and inodes if they are
|
||||
* allowed to accumulate. Since most websites only need thumbnails for recent
|
||||
* posts, it is okay to delete old thumbnails.
|
||||
*
|
||||
* Do not run this script if you have a gallery-style module where visitors
|
||||
* regularly view old posts. This will force thumbnails to be regenerated,
|
||||
* increasing the server load and making your pages load slower.
|
||||
*
|
||||
* This script only works on Unix-like operating systems where the 'find'
|
||||
* command is available.
|
||||
*/
|
||||
if (!defined('RX_VERSION'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
// Initialize the exit status.
|
||||
$exit_status = 0;
|
||||
|
||||
// Delete thumbnails older than this number of days.
|
||||
$days = intval($args[0] ?? 0) ?: 90;
|
||||
|
||||
// Delete old thumbnails.
|
||||
passthru(sprintf('find %s -type f -mtime +%d -delete', escapeshellarg(RX_BASEDIR . 'files/thumbnails'), abs($days)), $result);
|
||||
if ($result == 0)
|
||||
{
|
||||
echo "Successfully deleted thumbnails older than $days days.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Error while deleting thumbnails older than $days days.\n";
|
||||
$exit_status = $result;
|
||||
}
|
||||
|
||||
// Set the exit status if there were any errors.
|
||||
if ($exit_status != 0)
|
||||
{
|
||||
exit($exit_status);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue