Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Fixing the shell.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Aug 12, 2016
1 parent 3bcbae1 commit 0a56dbc
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Shell/PurifierShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ protected function _getTable()
$table = TableRegistry::get($this->args[0]);
$connection = $table->connection();
$tables = $connection->schemaCollection()->listTables();
if (!in_array($this->args[0], $tables)) {
$this->abort(__d('Burzum/HtmlPurifier', 'Table `{0}` does not exist in connection `{1}`!', $this->args[0], $connection->configName()));
if (!in_array($table->table(), $tables)) {
$this->abort(__d('Burzum/HtmlPurifier', 'Table `{0}` does not exist in connection `{1}`!', $table->table(), $connection->configName()));
}
return $table;
}

/**
Expand All @@ -54,6 +55,7 @@ protected function _getFields(Table $table)
$this->abort(sprintf('Table `%s` is missing the field `%s`.', $table->table(), $field));
}
}

return $fields;
}

Expand Down Expand Up @@ -95,11 +97,11 @@ public function purify()

$this->helper('progress')->output([
'total' => $total,
'callback' => function ($progress) use ($total, $table) {
'callback' => function ($progress) use ($total, $table, $fields) {
$chunkSize = 25;
$chunkCount = 0;
while ($chunkCount <= $total) {
$this->_process($table, $chunkCount, $chunkSize);
$this->_process($table, $chunkCount, $chunkSize, $fields);
$chunkCount = $chunkCount + $chunkSize;
$progress->increment($chunkSize);
$progress->draw();
Expand All @@ -117,14 +119,12 @@ public function purify()
* @param int $chunkSize
* @return void
*/
protected function _process(Table $table, $chunkCount, $chunkSize)
{
protected function _process(Table $table, $chunkCount, $chunkSize, $fields) {
$query = $table->find();
if ($table->hasFinder('purifier')) {
$query->find('purifier');
}

$fields = explode(',', $this->param('fields'));
$fields[] = $table->primaryKey();

$results = $query
Expand All @@ -143,16 +143,15 @@ protected function _process(Table $table, $chunkCount, $chunkSize)
$table->save($result);
$chunkCount++;
} catch (\Exception $e) {
$this->error($e->getMessage());
$this->abort($e->getMessage());
}
}
}

/**
* {@inheritDoc}
*/
public function getOptionParser()
{
public function getOptionParser() {
$parser = parent::getOptionParser();

$parser->description([
Expand Down

0 comments on commit 0a56dbc

Please sign in to comment.