Skip to content

Commit

Permalink
Language entries may be locked, disallowing further edits unless forced.
Browse files Browse the repository at this point in the history
Signed-off-by: William <[email protected]>
  • Loading branch information
William committed Oct 25, 2013
1 parent adf8193 commit 11b2770
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
19 changes: 11 additions & 8 deletions src/Waavi/Translation/Models/LanguageEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LanguageEntry extends WaaviModel {
'item' => 'required', // Entry code.
'text' => 'required', // Translation text.
'unstable' => '', // If this flag is set to true, the text in the default language has changed since this entry was last updated.
'overwrite' => '', // If this flag is set to false, then this entry may not be overwritten by a file entry.
'locked' => '', // If this flag is set to true, then this entry's text may not be edited.
);

/**
Expand Down Expand Up @@ -58,17 +58,20 @@ public function original($defaultLanguage)
* @param boolean $isDefault
* @return boolean
*/
public function updateText($text, $isDefault = false)
public function updateText($text, $isDefault = false, $lock = false, $force = false)
{
$this->text = $text;
if ($this->save()) {
if ($isDefault) {
$saved = false;

// If the text is locked, do not allow editing:
if (!$this->locked || $force) {
$this->text = $text;
$this->locked = $lock;
$saved = $this->save();
if ($saved && $isDefault) {
$this->flagSiblingsUnstable();
}
return true;
} else {
return false;
}
return $saved;
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/Waavi/Translation/Providers/LanguageEntryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,9 @@ public function loadArray(array $lines, $language, $group, $namespace = null, $i
->where('language_id', '=', $language->id)
->first();

// If the entry already exists, its text is different from the parameters, and it may be overwritten, we do so:
// If the entry already exists, we update the text:
if ($entry) {
if ($entry->text != $text && $entry->overwrite) {
$entry->text = $text;
if($entry->save() && $isDefault) {
$entry->flagSiblingsUnstable();
}
}
$entry->updateText($text, $isDefault);
}
// The entry doesn't exist:
else {
Expand Down
34 changes: 34 additions & 0 deletions src/migrations/2013_10_25_180009_rename_overwrite_to_locked.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;

class RenameOverwriteToLocked extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('language_entries', function($table){
$table->boolean('locked')->after('unstable')->default(0);
});
// Change the sign of locked for all entries that do not allow overwrite:
DB::table('language_entries')->where('overwrite', '0')->update(array('locked' => '1'));
Schema::table('language_entries', function($table){
$table->dropColumn('overwrite');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}

}

0 comments on commit 11b2770

Please sign in to comment.