From d10a29598df86b809121379e48b53d811b18c82e Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Fri, 20 May 2016 18:35:40 +0200 Subject: [PATCH] prevent deletion of WP Users segment in Segments listing --- lib/Models/Model.php | 2 +- lib/Models/Segment.php | 20 ++++++++++++++++++++ lib/Models/Subscriber.php | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Models/Model.php b/lib/Models/Model.php index ca283a469c..9cc28c7d6c 100644 --- a/lib/Models/Model.php +++ b/lib/Models/Model.php @@ -72,7 +72,7 @@ class Model extends \Sudzy\ValidModel { static function bulkTrash($orm) { $model = get_called_class(); return self::bulkAction($orm, function($ids) use($model) { - self::rawExecute(join(' ', array( + self::rawExecute(join(' ', array( 'UPDATE `'.$model::$_table.'`', 'SET `deleted_at`=NOW()', 'WHERE `id` IN ('.rtrim(str_repeat('?,', count($ids)), ',').')' diff --git a/lib/Models/Segment.php b/lib/Models/Segment.php index a741479dfe..f94a994e46 100644 --- a/lib/Models/Segment.php +++ b/lib/Models/Segment.php @@ -190,4 +190,24 @@ class Segment extends Model { static function getPublic() { return self::getPublished()->where('type', 'default')->orderByAsc('name'); } + + static function bulkTrash($orm) { + return parent::bulkAction($orm, function($ids) { + parent::rawExecute(join(' ', array( + 'UPDATE `'.self::$_table.'`', + 'SET `deleted_at`=NOW()', + 'WHERE `id` IN ('.rtrim(str_repeat('?,', count($ids)), ',').')', + 'AND `type` = "default"' + )), $ids); + }); + } + + static function bulkDelete($orm) { + return parent::bulkAction($orm, function($ids) { + // delete segments (only default) + Segment::whereIn('id', $ids) + ->where('type', 'default') + ->deleteMany(); + }); + } } \ No newline at end of file diff --git a/lib/Models/Subscriber.php b/lib/Models/Subscriber.php index 431fdb4625..990ed3927c 100644 --- a/lib/Models/Subscriber.php +++ b/lib/Models/Subscriber.php @@ -597,7 +597,7 @@ class Subscriber extends Model { static function bulkTrash($orm) { return parent::bulkAction($orm, function($ids) { - parent::rawExecute(join(' ', array( + parent::rawExecute(join(' ', array( 'UPDATE `'.self::$_table.'`', 'SET `deleted_at`=NOW()', 'WHERE `id` IN ('.rtrim(str_repeat('?,', count($ids)), ',').')',