Move all CLI scripts except common.cron to the "scripts" directory under the corresponding module

This commit is contained in:
Kijin Sung 2025-05-21 18:07:04 +09:00
parent 792ea89e64
commit 9ca2f79dce
14 changed files with 490 additions and 394 deletions

View file

@ -1,58 +1,8 @@
<?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.
* This script is @deprecated.
* Please invoke: php index.php file.cleanEmptyDirs
*/
require_once __DIR__ . '/common.php';
// 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);
}
require_once RX_BASEDIR . 'modules/file/scripts/cleanEmptyDirs.php';

View file

@ -1,98 +1,8 @@
<?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.
* This script is @deprecated.
* Please invoke: php index.php file.cleanGarbageFiles
*/
require_once __DIR__ . '/common.php';
// Delete garbage files older than this number of days.
$days = 10;
// Initialize the exit status.
$exit_status = 0;
// Initialize objects.
$oDB = DB::getInstance();
$oFileController = getController('file');
// Find and delete files where isvalid = N.
$args = new stdClass;
$args->isvalid = 'N';
$args->list_count = 50;
$args->regdate_before = date('YmdHis', time() - ($days * 86400));
while (true)
{
$output = executeQueryArray('file.getFileList', $args);
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 aborted file chunks older than $days days.\n";
}
else
{
echo "Error while deleting aborted file chunks older than $days days.\n";
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}
require_once RX_BASEDIR . 'modules/file/scripts/cleanGarbageFiles.php';

View file

@ -1,63 +1,8 @@
<?php
/**
* This script deletes old message attachments.
*
* Files attached to member messages are not viewable by other users, but they
* take up space on the server. You may want to delete them after a certain
* number of days in order to prevent users from using messages as a sort of
* private storage space.
* This script is @deprecated.
* Please invoke: php index.php communication.cleanMessageFiles
*/
require_once __DIR__ . '/common.php';
// Delete attachments older than this number of days.
$days = 30;
// Initialize the exit status.
$exit_status = 0;
// Initialize objects.
$oDB = DB::getInstance();
$oFileController = getController('file');
// Find and delete files where upload_target_type = msg.
$args = new stdClass;
$args->upload_target_type = 'msg';
$args->list_count = 50;
$args->regdate_before = date('YmdHis', time() - ($days * 86400));
while (true)
{
$output = executeQueryArray('file.getFileList', $args);
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 message attachments older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
break;
}
}
if ($exit_status == 0)
{
echo "Successfully deleted all message attachments older than $days days.\n";
}
require_once RX_BASEDIR . 'modules/communication/scripts/cleanMessageFiles.php';

View file

@ -1,66 +1,8 @@
<?php
/**
* This script deletes old logs from the database.
*
* Rhymix produces various logs that can increase the size of the database
* unnecessarily if not cleaned. This script removes old logs.
* This script is @deprecated.
* Please invoke: php index.php module.cleanMiscLogs
*/
require_once __DIR__ . '/common.php';
// Delete logs older than this number of days.
$days = 30;
// Initialize the exit status.
$exit_status = 0;
// Delete advanced mailer mail logs.
$args = new stdClass;
$args->regdate = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('advanced_mailer.deleteMailLogs', $args);
if ($output->toBool())
{
echo "Successfully deleted all mail logs older than $days days.\n";
}
else
{
echo "Error while deleting mail logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
}
// Delete advanced mailer SMS logs.
$args = new stdClass;
$args->regdate = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('advanced_mailer.deleteSMSLogs', $args);
if ($output->toBool())
{
echo "Successfully deleted all SMS logs older than $days days.\n";
}
else
{
echo "Error while deleting SMS logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 12;
}
// Delete spamfilter logs.
$args = new stdClass;
$args->regdate = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('spamfilter.deleteLog', $args);
if ($output->toBool())
{
echo "Successfully deleted all spamfilter logs older than $days days.\n";
}
else
{
echo "Error while deleting spamfilter logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 12;
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}
require_once RX_BASEDIR . 'modules/module/scripts/cleanMiscLogs.php';

View file

@ -1,40 +1,8 @@
<?php
/**
* This script deletes old notifications.
*
* Notifications must be dismissed as quickly as possible in order to prevent
* the ncenterlite_notify table from becoming too large. For best performance,
* you should run this script at least once every few days.
* This script is @deprecated.
* Please invoke: php index.php ncenterlite.cleanNotifications
*/
require_once __DIR__ . '/common.php';
// Delete notifications older than this number of days.
$days = 30;
// Initialize the exit status.
$exit_status = 0;
// Execute the query.
$args = new stdClass;
$args->old_date = date('YmdHis', time() - ($days * 86400));
$output = executeQuery('ncenterlite.deleteNotifyAll', $args);
if ($output->toBool())
{
echo "Successfully deleted all notifications older than $days days.\n";
$delete_obj = (object)array('regdate' => time());
Rhymix\Framework\Cache::clearGroup('ncenterlite');
Rhymix\Framework\Storage::writePHPData(\RX_BASEDIR . 'files/cache/ncenterlite/new_notify/delete_date.php', $delete_obj);
}
else
{
echo "Error while deleting notifications older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}
require_once RX_BASEDIR . 'modules/ncenterlite/scripts/cleanNotifications.php';

View file

@ -1,41 +1,8 @@
<?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.
* This script is @deprecated.
* Please invoke: php index.php file.cleanThumbnails
*/
require_once __DIR__ . '/common.php';
// Delete thumbnails older than this number of days.
$days = 90;
// Initialize the exit status.
$exit_status = 0;
// 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 all 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);
}
require_once RX_BASEDIR . 'modules/file/scripts/cleanThumbnails.php';

View file

@ -1,63 +1,8 @@
<?php
/**
* This script updates all modules.
*
* Running this script on the CLI is better than clicking 'update' in the
* admin dashboard because some module updates may take a long time.
* This script is @deprecated.
* Please invoke: php index.php module.updateAllModules
*/
require_once __DIR__ . '/common.php';
Context::init();
$oModuleModel = getModel('module');
// Get the list of modules that need to be updated.
$module_list = $oModuleModel->getModuleList();
$need_install = array();
$need_update = array();
foreach($module_list as $key => $value)
{
if($value->need_install)
{
$need_install[] = $value->module;
}
if($value->need_update)
{
$need_update[] = $value->module;
}
}
// Install all modules.
$oInstallController = InstallController::getInstance();
foreach ($need_install as $module)
{
try
{
echo 'Installing ' . $module . '...' . PHP_EOL;
$oInstallController->installModule($module, './modules/' . $module);
}
catch (\Exception $e)
{
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
}
// Update all modules.
foreach ($need_update as $module)
{
try
{
echo 'Updating ' . $module . '...' . PHP_EOL;
$oInstallController->updateModule($module);
}
catch (\Exception $e)
{
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}
require_once RX_BASEDIR . 'modules/module/scripts/updateAllModules.php';

View file

@ -0,0 +1,67 @@
<?php
/**
* This script deletes old message attachments.
*
* Files attached to member messages are not viewable by other users, but they
* take up space on the server. You may want to delete them after a certain
* number of days in order to prevent users from using messages as a sort of
* private storage space.
*/
if (!defined('RX_VERSION'))
{
exit;
}
// Initialize the exit status.
$exit_status = 0;
// Delete attachments older than this number of days.
$days = intval($args[0] ?? 0) ?: 30;
// Initialize objects.
$oDB = DB::getInstance();
$oFileController = FileController::getInstance();
// Find and delete files where upload_target_type = msg.
while (true)
{
$output = executeQueryArray('file.getFileList', [
'upload_target_type' => 'msg',
'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 message attachments older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
break;
}
}
if ($exit_status == 0)
{
echo "Successfully deleted all message attachments older than $days days.\n";
}

View 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);
}

View 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);
}

View 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);
}

View file

@ -0,0 +1,84 @@
<?php
/**
* This script deletes old logs from the database.
*
* Rhymix produces various logs that can increase the size of the database
* unnecessarily if not cleaned. This script removes old logs.
*/
if (!defined('RX_VERSION'))
{
exit;
}
// Initialize the exit status.
$exit_status = 0;
// Delete logs older than this number of days.
$days = intval($args[0] ?? 0) ?: 30;
// Delete advanced mailer email logs.
$output = executeQuery('advanced_mailer.deleteMailLogs', [
'regdate' => date('YmdHis', time() - ($days * 86400)),
]);
if ($output->toBool())
{
echo "Successfully deleted all email logs older than $days days.\n";
}
else
{
echo "Error while deleting email logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
}
// Delete advanced mailer SMS logs.
$output = executeQuery('advanced_mailer.deleteSMSLogs', [
'regdate' => date('YmdHis', time() - ($days * 86400)),
]);
if ($output->toBool())
{
echo "Successfully deleted all SMS logs older than $days days.\n";
}
else
{
echo "Error while deleting SMS logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 12;
}
// Delete advanced mailer Push logs.
$output = executeQuery('advanced_mailer.deletePushLogs', [
'regdate' => date('YmdHis', time() - ($days * 86400)),
]);
if ($output->toBool())
{
echo "Successfully deleted all Push logs older than $days days.\n";
}
else
{
echo "Error while deleting Push logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 13;
}
// Delete spamfilter logs.
$output = executeQuery('spamfilter.deleteLog', [
'regdate' => date('YmdHis', time() - ($days * 86400)),
]);
if ($output->toBool())
{
echo "Successfully deleted all spamfilter logs older than $days days.\n";
}
else
{
echo "Error while deleting spamfilter logs older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 21;
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}

View file

@ -0,0 +1,67 @@
<?php
/**
* This script updates all modules.
*
* When upgrading from a very old version, it is safer to run this script
* on the CLI than clicking 'update' in the admin dashboard.
* This is because some module updates may take a long time.
*
* Note that if you use APC cache, you may need to reset the cache
* in the admin dashboard after running this script.
*/
if (!defined('RX_VERSION'))
{
exit;
}
// Get the list of modules that need to be updated.
$module_list = ModuleModel::getModuleList();
$need_install = array();
$need_update = array();
foreach ($module_list as $key => $value)
{
if ($value->need_install)
{
$need_install[] = $value->module;
}
if ($value->need_update)
{
$need_update[] = $value->module;
}
}
// Install all modules.
$oInstallController = InstallController::getInstance();
foreach ($need_install as $module)
{
try
{
echo 'Installing ' . $module . '...' . PHP_EOL;
$oInstallController->installModule($module, './modules/' . $module);
}
catch (\Exception $e)
{
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
}
// Update all modules.
foreach ($need_update as $module)
{
try
{
echo 'Updating ' . $module . '...' . PHP_EOL;
$oInstallController->updateModule($module);
}
catch (\Exception $e)
{
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}

View file

@ -0,0 +1,44 @@
<?php
/**
* This script deletes old notifications.
*
* Notifications must be dismissed as quickly as possible in order to prevent
* the ncenterlite_notify table from becoming too large. For best performance,
* you should run this script at least once every few days.
*/
if (!defined('RX_VERSION'))
{
exit;
}
// Initialize the exit status.
$exit_status = 0;
// Delete notifications older than this number of days.
$days = intval($args[0] ?? 0) ?: 30;
// Execute the query.
$output = executeQuery('ncenterlite.deleteNotifyAll', [
'old_date' => date('YmdHis', time() - ($days * 86400)),
]);
if ($output->toBool())
{
echo "Successfully deleted all notifications older than $days days.\n";
$delete_obj = (object)array('regdate' => time());
Rhymix\Framework\Cache::clearGroup('ncenterlite');
Rhymix\Framework\Storage::writePHPData(\RX_BASEDIR . 'files/cache/ncenterlite/new_notify/delete_date.php', $delete_obj);
}
else
{
echo "Error while deleting notifications older than $days days.\n";
echo $output->getMessage() . "\n";
$exit_status = 11;
}
// Set the exit status if there were any errors.
if ($exit_status != 0)
{
exit($exit_status);
}