cleanup and bugfix on bulk actions

This commit is contained in:
Jonathan Labreuille
2016-02-15 15:50:47 +01:00
parent 6c0f6a07cd
commit 67036ddb61
2 changed files with 11 additions and 12 deletions

View File

@@ -56,9 +56,6 @@ class Initializer {
\ORM::configure('username', Env::$db_username);
\ORM::configure('password', Env::$db_password);
\ORM::configure('logging', WP_DEBUG);
\ORM::configure('logger', function($query, $time) {
error_log($query);
});
\ORM::configure('driver_options', array(
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET TIME_ZONE = "+00:00"'

View File

@@ -109,17 +109,19 @@ class Model extends \Sudzy\ValidModel {
static function bulkAction($orm, $callback = false) {
$total = $orm->count();
$models = $orm->select('id')
->offset(null)
->limit(null)
->findArray();
if($total > 0) {
$models = $orm->select('id')
->offset(null)
->limit(null)
->findArray();
$ids = array_map(function($model) {
return (int)$model['id'];
}, $models);
$ids = array_map(function($model) {
return (int)$model['id'];
}, $models);
if(is_callable($callback)) {
$callback($ids);
if(is_callable($callback)) {
$callback($ids);
}
}
return $total;