@@ -35,9 +35,10 @@ protected function _getTable()
3535 $ table = TableRegistry::get ($ this ->args [0 ]);
3636 $ connection = $ table ->connection ();
3737 $ tables = $ connection ->schemaCollection ()->listTables ();
38- if (!in_array ($ this -> args [ 0 ] , $ tables )) {
39- $ this ->abort (__d ('Burzum/HtmlPurifier ' , 'Table `{0}` does not exist in connection `{1}`! ' , $ this -> args [ 0 ] , $ connection ->configName ()));
38+ if (!in_array ($ table -> table () , $ tables )) {
39+ $ this ->abort (__d ('Burzum/HtmlPurifier ' , 'Table `{0}` does not exist in connection `{1}`! ' , $ table -> table () , $ connection ->configName ()));
4040 }
41+ return $ table ;
4142 }
4243
4344 /**
@@ -54,6 +55,7 @@ protected function _getFields(Table $table)
5455 $ this ->abort (sprintf ('Table `%s` is missing the field `%s`. ' , $ table ->table (), $ field ));
5556 }
5657 }
58+
5759 return $ fields ;
5860 }
5961
@@ -95,11 +97,11 @@ public function purify()
9597
9698 $ this ->helper ('progress ' )->output ([
9799 'total ' => $ total ,
98- 'callback ' => function ($ progress ) use ($ total , $ table ) {
100+ 'callback ' => function ($ progress ) use ($ total , $ table, $ fields ) {
99101 $ chunkSize = 25 ;
100102 $ chunkCount = 0 ;
101103 while ($ chunkCount <= $ total ) {
102- $ this ->_process ($ table , $ chunkCount , $ chunkSize );
104+ $ this ->_process ($ table , $ chunkCount , $ chunkSize, $ fields );
103105 $ chunkCount = $ chunkCount + $ chunkSize ;
104106 $ progress ->increment ($ chunkSize );
105107 $ progress ->draw ();
@@ -117,14 +119,12 @@ public function purify()
117119 * @param int $chunkSize
118120 * @return void
119121 */
120- protected function _process (Table $ table , $ chunkCount , $ chunkSize )
121- {
122+ protected function _process (Table $ table , $ chunkCount , $ chunkSize , $ fields ) {
122123 $ query = $ table ->find ();
123124 if ($ table ->hasFinder ('purifier ' )) {
124125 $ query ->find ('purifier ' );
125126 }
126127
127- $ fields = explode (', ' , $ this ->param ('fields ' ));
128128 $ fields [] = $ table ->primaryKey ();
129129
130130 $ results = $ query
@@ -143,16 +143,15 @@ protected function _process(Table $table, $chunkCount, $chunkSize)
143143 $ table ->save ($ result );
144144 $ chunkCount ++;
145145 } catch (\Exception $ e ) {
146- $ this ->error ($ e ->getMessage ());
146+ $ this ->abort ($ e ->getMessage ());
147147 }
148148 }
149149 }
150150
151151 /**
152152 * {@inheritDoc}
153153 */
154- public function getOptionParser ()
155- {
154+ public function getOptionParser () {
156155 $ parser = parent ::getOptionParser ();
157156
158157 $ parser ->description ([
0 commit comments