for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Base class for migrations whose only purpose is to add a setting to the
* settings table. Implementations only have to implement the getName() and
* getDefaultValue() methods, the actual migration is handled here.
*
* @author Sam Stenvall <[email protected]>
* @copyright Copyright © Sam Stenvall 2014-
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
*/
abstract class AddSettingMigration extends CDbMigration
{
* @return string the name of the new setting
abstract public function getName();
* @return string the default value of the new setting
abstract public function getDefaultValue();
* Adds the setting with its default value to the settings table. Nothing
* is done if the setting already exists.
* @return type
public function up()
$name = $this->getName();
// Check if the setting exists
$command = $this->dbConnection->createCommand('SELECT * FROM settings WHERE name = :name');
$settingExists = $command->queryRow(true, array(':name' => $name)) !== false;
if ($settingExists)
return true;
return true
true
type
$this->insert('settings', array(
'name'=>$name,
'value'=>(string)$this->getDefaultValue()));
}
* Removes the setting
public function down()
$this->delete('settings', 'name = :name', array(
':name'=>$this->getName()));