Skip to content

Commit

Permalink
Dev: db field names coherence
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Apr 15, 2019
1 parent d2adb97 commit 90b3bdc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@


$config['versionnumber'] = '3.17.2';
$config['dbversionnumber'] = 356;
$config['dbversionnumber'] = 357;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30083';
Expand Down
2 changes: 1 addition & 1 deletion application/core/LsDefaultDataSets.php
Expand Up @@ -222,7 +222,7 @@ public static function getSurveygroupData()
'template' => null,
'description' => 'Default survey group',
'sortorder' => 0,
'owner_uid' => 1,
'owner_id' => 1,
'parent_id' => null,
'created' => date('Y-m-d H:i:s'),
'modified' => date('Y-m-d H:i:s'),
Expand Down
18 changes: 15 additions & 3 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -2274,7 +2274,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
if ($iOldDBVersion < 354) {
$oTransaction = $oDB->beginTransaction();
$surveymenuTable = Yii::app()->db->schema->getTable('{{surveymenu}}');

if (!isset($surveymenuTable->columns['showincollapse'])) {
$oDB->createCommand()->addColumn('{{surveymenu}}', 'showincollapse', 'integer DEFAULT 0');
}
Expand All @@ -2294,7 +2294,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
$aIdMap[$aSurveymenu['name']] = $aSurveymenu['id'];
}
switchMSSQLIdentityInsert('surveymenu', false);

$aDefaultSurveyMenuEntries = LsDefaultDataSets::getSurveyMenuEntryData();
foreach($aDefaultSurveyMenuEntries as $i => $aSurveymenuentry) {
$oDB->createCommand()->delete('{{surveymenu_entries}}', 'name=:name', [':name' => $aSurveymenuentry['name']]);
Expand Down Expand Up @@ -2323,7 +2323,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
->where('name=:name', [':name' => $aSurveymenu['name']])
->queryScalar();
}

$aDefaultSurveyMenuEntries = LsDefaultDataSets::getSurveyMenuEntryData();
foreach($aDefaultSurveyMenuEntries as $i => $aSurveymenuentry) {
$oDB->createCommand()->delete('{{surveymenu_entries}}', 'name=:name', [':name' => $aSurveymenuentry['name']]);
Expand Down Expand Up @@ -2374,6 +2374,18 @@ function db_upgrade_all($iOldDBVersion, $bSilent = false)
$oDB->createCommand()->update('{{settings_global}}', ['stg_value'=>356], "stg_name='DBVersion'");
$oTransaction->commit();
}




if ($iOldDBVersion < 357) {
$oTransaction = $oDB->beginTransaction();
//// IKI
$oDB->createCommand()->renameColumn('{{surveys_groups}}','owner_uid','owner_id');
$oDB->createCommand()->update('{{settings_global}}', ['stg_value'=>357], "stg_name='DBVersion'");
$oTransaction->commit();
}

} catch (Exception $e) {
Yii::app()->setConfig('Updating', false);
$oTransaction->rollback();
Expand Down
16 changes: 8 additions & 8 deletions application/models/SurveysGroups.php
Expand Up @@ -9,7 +9,7 @@
* @property string $title
* @property string $description
* @property integer $sortorder
* @property integer $owner_uid
* @property integer $owner_id
* @property integer $parent_id
* @property string $created
* @property string $modified
Expand All @@ -36,14 +36,14 @@ public function rules()
// will receive user inputs.
return array(
array('name, sortorder, created_by, title', 'required'),
array('sortorder, owner_uid, parent_id, created_by', 'numerical', 'integerOnly'=>true),
array('sortorder, owner_id, parent_id, created_by', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>45),
array('name', 'match', 'pattern'=> '/^[A-Za-z0-9_\.]+$/u','message'=> gT('Group name can contain only alphanumeric character, underscore or dot.')),
array('title', 'length', 'max'=>100),
array('description, created, modified', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('gsid, name, title, description, owner_uid, parent_id, created, modified, created_by', 'safe', 'on'=>'search'),
array('gsid, name, title, description, owner_id, parent_id, created, modified, created_by', 'safe', 'on'=>'search'),
);
}

Expand All @@ -56,7 +56,7 @@ public function relations()
// class name for the relations automatically generated below.
return array(
'parentgroup' => array(self::BELONGS_TO, 'SurveysGroups', array('parent_id' => 'gsid'), 'together' => true),
'owner' => array(self::BELONGS_TO, 'User', 'owner_uid', 'together' => true),
'owner' => array(self::BELONGS_TO, 'User', 'owner_id', 'together' => true),
);
}

Expand All @@ -71,7 +71,7 @@ public function attributeLabels()
'title' => gT('Title'),
'description' => gT('Description'),
'sortorder' => gT('Sort order'),
'owner_uid' => gT('Owner UID'),
'owner_id' => gT('Owner UID'),
'parent_id' => gT('Parent group'),
'created' => gT('Created on'),
'modified' => gT('Modified on'),
Expand Down Expand Up @@ -183,7 +183,7 @@ public function search()
$criteria->compare('title', $this->title, true);
$criteria->compare('description', $this->description, true);
$criteria->compare('sortorder', $this->sortorder);
$criteria->compare('owner_uid', $this->owner_uid);
$criteria->compare('owner_id', $this->owner_id);
$criteria->compare('parent_id', $this->parent_id);
$criteria->compare('created', $this->created, true);
$criteria->compare('modified', $this->modified, true);
Expand All @@ -200,7 +200,7 @@ public function search()
LEFT JOIN {{permissions}} AS permissions ON (permissions.entity_id = surveys.sid AND permissions.permission='survey' AND permissions.entity='survey' AND permissions.uid='".Yii::app()->user->id."') ",
));

$criteriaPerm->compare('t.owner_uid', Yii::app()->user->id, false);
$criteriaPerm->compare('t.owner_id', Yii::app()->user->id, false);
$criteriaPerm->compare('surveys.owner_id', Yii::app()->user->id, false, 'OR');
$criteriaPerm->compare('permissions.read_p', '1', false, 'OR');
$criteriaPerm->compare('t.gsid', '1', false, 'OR'); // "default" survey group
Expand Down Expand Up @@ -286,7 +286,7 @@ public static function getSurveyGroupsList()
$criteria = new CDbCriteria;

if (!Permission::model()->hasGlobalPermission("surveys", 'read')) {
$criteria->compare('t.owner_uid', Yii::app()->user->id, false);
$criteria->compare('t.owner_id', Yii::app()->user->id, false);
$criteria->compare('t.gsid', '1', false, 'OR'); // "default" survey group
}

Expand Down
3 changes: 1 addition & 2 deletions application/views/admin/surveysgroups/_form.php
Expand Up @@ -20,7 +20,7 @@

<?php echo $form->errorSummary($model); ?>

<?php echo $form->hiddenField($model,'owner_uid'); ?>
<?php echo $form->hiddenField($model,'owner_id'); ?>
<?php echo $form->hiddenField($model,'gsid'); ?>

<?php if($model->isNewRecord): ?>
Expand Down Expand Up @@ -67,4 +67,3 @@

</div><!-- form -->
</div>

0 comments on commit 90b3bdc

Please sign in to comment.