Permalink
Browse files

switch to new iterate mode

  • Loading branch information...
flack committed Oct 9, 2017
1 parent a6f8e16 commit 638d49d7cdb8a79989f7103ad842640b7375d575
View
@@ -30,7 +30,7 @@
"michelf/php-markdown": "~1.3",
"midgard/midgardmvc-helper-urlize": "^1.1.1",
"openpsa/installer": "^1.0",
"openpsa/midgard-portable": "^1.1.0",
"openpsa/midgard-portable": "^1.2.0",
"openpsa/ranger": ">=0.3.0",
"openpsa/universalfeedcreator": "^1.8.2",
"paragonie/random_compat": "^2.0",
@@ -16,8 +16,7 @@ public function execute()
if (midcom::get()->config->get('auth_login_session_timeout')) {
$qb = new midgard_query_builder('midcom_core_login_session_db');
$qb->add_constraint('timestamp', '<', time() - midcom::get()->config->get('auth_login_session_timeout'));
$qb->set_limit(500);
foreach ($qb->execute() as $tmp) {
foreach ($qb->iterate() as $tmp) {
if (!$tmp->purge()) {
$msg = "Failed to purge login session {$tmp->id}, last Midgard error was: " . midcom_connection::get_error_string();
$this->print_error($msg, $tmp);
@@ -58,28 +58,22 @@ public function execute()
}
}
public function process_class($mgdschema, $limit = 500, $offset = 0)
public function process_class($mgdschema)
{
$cut_off = $this->get_cutoff();
$qb = new midgard_query_builder($mgdschema);
$qb->add_constraint('metadata.deleted', '<>', 0);
$qb->add_constraint('metadata.revised', '<', gmdate('Y-m-d H:i:s', $cut_off));
$qb->include_deleted();
if ($limit) {
$qb->set_limit($limit);
}
if ($offset) {
$qb->set_offset($offset);
}
$objects = $qb->execute();
$stats = [
'found' => count($objects),
'found' => 0,
'purged' => 0,
'errors' => []
];
foreach ($objects as $obj) {
foreach ($qb->iterate() as $obj) {
$stats['found']++;
if (!$obj->purge()) {
$stats['errors'][] = "Failed to purge {$obj->guid}, deleted: {$obj->metadata->deleted}, revised: {$obj->metadata->revised}. errstr: " . midcom_connection::get_error_string();
debug_print_r('Purge failed for object', $obj);
@@ -2,7 +2,6 @@
midcom::get()->auth->require_admin_user();
midcom::get()->disable_limits();
ob_implicit_flush(true);
$chunk_size = 1000;
if (!isset($_GET['days'])) {
$grace_days = midcom::get()->config->get('cron_purge_deleted_after');
@@ -18,21 +17,19 @@
echo "<pre>\n";
foreach ($handler->get_classes() as $mgdschema) {
$errors = 0;
echo "<p><strong>Processing class {$mgdschema}</strong>\n";
do {
$stats = $handler->process_class($mgdschema, $chunk_size, $errors);
$stats = $handler->process_class($mgdschema);
foreach ($stats['errors'] as $error) {
$errors++;
echo ' ERROR:' . $error . "\n";
}
if ($stats['found'] > 0) {
echo " Purged {$stats['purged']} deleted objects, " . count($stats['errors']) . " failures\n";
} else {
echo " No matching objects found\n";
}
foreach ($stats['errors'] as $error) {
$errors++;
echo ' ERROR:' . $error . "\n";
}
if ($stats['found'] > 0) {
echo " Purged {$stats['purged']} deleted objects, " . count($stats['errors']) . " failures\n";
} else {
echo " No matching objects found\n";
}
} while ($stats['found'] == $chunk_size);
echo "<p>";
}
@@ -56,7 +56,7 @@ public function __construct($index_name = null)
* Note, that $document may also be an array of documents without further
* changes to this backend.
*
* @param array $documents A list of midcom_services_indexer_document objects.
* @param midcom_services_indexer_document[] $documents A list of objects.
* @return boolean Indicating success.
*/
public function index(array $documents)

0 comments on commit 638d49d

Please sign in to comment.