@@ -35,9 +35,10 @@ protected function _getTable()
35
35
$ table = TableRegistry::get ($ this ->args [0 ]);
36
36
$ connection = $ table ->connection ();
37
37
$ 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 ()));
40
40
}
41
+ return $ table ;
41
42
}
42
43
43
44
/**
@@ -54,6 +55,7 @@ protected function _getFields(Table $table)
54
55
$ this ->abort (sprintf ('Table `%s` is missing the field `%s`. ' , $ table ->table (), $ field ));
55
56
}
56
57
}
58
+
57
59
return $ fields ;
58
60
}
59
61
@@ -95,11 +97,11 @@ public function purify()
95
97
96
98
$ this ->helper ('progress ' )->output ([
97
99
'total ' => $ total ,
98
- 'callback ' => function ($ progress ) use ($ total , $ table ) {
100
+ 'callback ' => function ($ progress ) use ($ total , $ table, $ fields ) {
99
101
$ chunkSize = 25 ;
100
102
$ chunkCount = 0 ;
101
103
while ($ chunkCount <= $ total ) {
102
- $ this ->_process ($ table , $ chunkCount , $ chunkSize );
104
+ $ this ->_process ($ table , $ chunkCount , $ chunkSize, $ fields );
103
105
$ chunkCount = $ chunkCount + $ chunkSize ;
104
106
$ progress ->increment ($ chunkSize );
105
107
$ progress ->draw ();
@@ -117,14 +119,12 @@ public function purify()
117
119
* @param int $chunkSize
118
120
* @return void
119
121
*/
120
- protected function _process (Table $ table , $ chunkCount , $ chunkSize )
121
- {
122
+ protected function _process (Table $ table , $ chunkCount , $ chunkSize , $ fields ) {
122
123
$ query = $ table ->find ();
123
124
if ($ table ->hasFinder ('purifier ' )) {
124
125
$ query ->find ('purifier ' );
125
126
}
126
127
127
- $ fields = explode (', ' , $ this ->param ('fields ' ));
128
128
$ fields [] = $ table ->primaryKey ();
129
129
130
130
$ results = $ query
@@ -143,16 +143,15 @@ protected function _process(Table $table, $chunkCount, $chunkSize)
143
143
$ table ->save ($ result );
144
144
$ chunkCount ++;
145
145
} catch (\Exception $ e ) {
146
- $ this ->error ($ e ->getMessage ());
146
+ $ this ->abort ($ e ->getMessage ());
147
147
}
148
148
}
149
149
}
150
150
151
151
/**
152
152
* {@inheritDoc}
153
153
*/
154
- public function getOptionParser ()
155
- {
154
+ public function getOptionParser () {
156
155
$ parser = parent ::getOptionParser ();
157
156
158
157
$ parser ->description ([
0 commit comments