Jalle19 /
xbmc-video-server
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Base class for migrations whose only purpose is to add a setting to the |
||
| 5 | * settings table. Implementations only have to implement the getName() and |
||
| 6 | * getDefaultValue() methods, the actual migration is handled here. |
||
| 7 | * |
||
| 8 | * @author Sam Stenvall <[email protected]> |
||
| 9 | * @copyright Copyright © Sam Stenvall 2014- |
||
| 10 | * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0 |
||
| 11 | */ |
||
| 12 | abstract class AddSettingMigration extends CDbMigration |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @return string the name of the new setting |
||
| 17 | */ |
||
| 18 | abstract public function getName(); |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return string the default value of the new setting |
||
| 22 | */ |
||
| 23 | abstract public function getDefaultValue(); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Adds the setting with its default value to the settings table. Nothing |
||
| 27 | * is done if the setting already exists. |
||
| 28 | * @return type |
||
| 29 | */ |
||
| 30 | public function up() |
||
| 31 | { |
||
| 32 | $name = $this->getName(); |
||
| 33 | |||
| 34 | // Check if the setting exists |
||
| 35 | $command = $this->dbConnection->createCommand('SELECT * FROM settings WHERE name = :name'); |
||
| 36 | $settingExists = $command->queryRow(true, array(':name' => $name)) !== false; |
||
| 37 | |||
| 38 | if ($settingExists) |
||
| 39 | return true; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 40 | |||
| 41 | $this->insert('settings', array( |
||
| 42 | 'name'=>$name, |
||
| 43 | 'value'=>(string)$this->getDefaultValue())); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Removes the setting |
||
| 48 | */ |
||
| 49 | public function down() |
||
| 50 | { |
||
| 51 | $this->delete('settings', 'name = :name', array( |
||
| 52 | ':name'=>$this->getName())); |
||
| 53 | } |
||
| 54 | |||
| 55 | } |