-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENHANCEMENT SlideType default value task (#158)
* ENHANCEMENT SlideType default value task BUGFIX check if LinkLabel isset in SlideLinkTask * UPDATE phpcs fix
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Dynamic\Flexslider\Task; | ||
|
||
use Dynamic\FlexSlider\Model\SlideImage; | ||
use SilverStripe\Dev\BuildTask; | ||
use SilverStripe\ORM\DB; | ||
|
||
/** | ||
* Class DefaultSlideTypeTask | ||
* @package Dynamic\Flexslider\Task | ||
*/ | ||
class DefaultSlideTypeTask extends BuildTask | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private static $segment = 'default-slide-type-task'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $title = 'Flexslider - Default Slide Type Task'; | ||
|
||
/** | ||
* @param \SilverStripe\Control\HTTPRequest $request | ||
*/ | ||
public function run($request) | ||
{ | ||
$this->setDefaults(); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function setDefaults() | ||
{ | ||
$default = SlideImage::singleton()->config()->get('defaults'); | ||
|
||
if (isset($default['SlideType'])) { | ||
$baseTable = SlideImage::singleton()->baseTable(); | ||
|
||
$tables = [ | ||
$baseTable, | ||
"{$baseTable}_Versions", | ||
"{$baseTable}_Live", | ||
]; | ||
|
||
foreach ($tables as $table) { | ||
$query = DB::query("SELECT * FROM \"{$table}\" WHERE \"SlideType\" IS NULL"); | ||
|
||
foreach ($this->yieldSingle($query) as $record) { | ||
DB::prepared_query( | ||
"UPDATE \"{$table}\" SET \"SlideType\" = ? WHERE \"ID\" = ?", | ||
[$default['SlideType'], $record['ID']] | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param $list | ||
* @return \Generator | ||
*/ | ||
protected function yieldSingle($list) | ||
{ | ||
foreach ($list as $item) { | ||
yield $item; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters