Last active
April 5, 2017 07:49
-
-
Save alexsoin/af7fa180be0e8093df6b50e9c45a734f to your computer and use it in GitHub Desktop.
Удаление старых версий пакетов в modx - Remove old versions of packages in modx. To run in console.
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 | |
define('MODX_API_MODE', true); | |
require 'index.php'; | |
$modx->getService('error', 'error.modError'); | |
$modx->setLogLevel(modX::LOG_LEVEL_ERROR); | |
$modx->setLogTarget('ECHO'); | |
if (!XPDO_CLI_MODE) { | |
echo '<pre>'; | |
} | |
$c = $modx->newQuery('transport.modTransportPackage'); | |
$c->select('package_name'); | |
$c->groupby('package_name'); | |
if ($c->prepare() && $c->stmt->execute()) { | |
while ($package = $c->stmt->fetchColumn()) { | |
$c2 = $modx->newQuery('transport.modTransportPackage', ['package_name' => $package]); | |
$c2->where(['installed:!=' => '0000-00-00 00:00:00']); | |
$c2->sortby('installed', 'desc'); | |
$c2->limit(1000, 1); | |
$c2->select('signature'); | |
if ($c2->prepare() && $c2->stmt->execute()) { | |
while ($signature = $c2->stmt->fetchColumn()) { | |
$res = $modx->runProcessor('workspace/packages/version/remove', ['signature' => $signature]); | |
if (!$res->isError()) { | |
echo $signature . " removed!\n"; | |
ob_flush(); | |
} else { | |
$modx->log(modX::LOG_LEVEL_ERROR, "Could not remove {$signature}:" . $res->getMessage()); | |
} | |
} | |
} | |
} | |
} | |
if (!XPDO_CLI_MODE) { | |
echo '</pre>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment