The xpdo's removeCollection only returns number of removed objects.
Is there any way to retrieved the removed objects as same as getCollection?
The case is that I'm using based class processor to remove data, and the output is parsed using the
response processor which expects an array of processed objects.
I assume a temporary object would handle the removed objects and be used as the removeCollection's output.
For your convenient, this is my processor:
<?php
class WebUsersOnlineRemoveTimeoutProcessor extends modObjectGetListProcessor {
public $classKey = 'OnlineUsers';
public $languageTopics = array();
public $defaultSortField = 'user_name';
public $checkListPermission = false;
public $objectType = 'modjochat.WebUsersOnlineRemoveTimeout';
/**
* Get the data of the query
* @return array
*/
public function getData() {
$data = array();
/* query for chunks */
$c = $this->modx->newQuery($this->classKey);
$c = $this->prepareQueryBeforeCount($c);
$data['total'] = $this->modx->getCount($this->classKey, $c);
$c = $this->prepareQueryAfterCount($c);
$sortClassKey = $this->getSortClassKey();
$sortKey = $this->modx->getSelectColumns($sortClassKey, $this->getProperty('sortAlias', $sortClassKey), '', array($this->getProperty('sort')));
if (empty($sortKey))
$sortKey = $this->getProperty('sort');
$c->sortby($sortKey, $this->getProperty('dir'));
$c->prepare();
$sql = $c->toSQL();
$this->modx->log(modX::LOG_LEVEL_ERROR, __FILE__ . ' ');
$this->modx->log(modX::LOG_LEVEL_ERROR, __METHOD__ . ' ');
$this->modx->log(modX::LOG_LEVEL_ERROR, __LINE__ . ': $sql ' . $sql);
$removed = $this->modx->removeCollection($this->classKey, $c);
if ($removed) {
$this->modx->log(modX::LOG_LEVEL_ERROR, __LINE__ . ': $removed ' . print_r($removed, 1));
}
$data['results'] = array();
return $data;
}
/**
* Can be used to adjust the query prior to the COUNT statement
*
* @param xPDOQuery $c
* @return xPDOQuery
*/
public function prepareQueryBeforeCount(xPDOQuery $c) {
$timeOut = time();
$c->where(array(
'timeout:<' => $timeOut
));
return $c;
}
}
return 'WebUsersOnlineRemoveTimeoutProcessor';
[ed. note: goldsky last edited this post 13 years, 8 months ago.]