1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-23 19:02:46 +01:00

Add meta column to conversations table

This commit is contained in:
FreeScout 2022-12-17 22:20:43 -08:00
parent 1e39e35251
commit d6ef9ddc37
2 changed files with 68 additions and 49 deletions

View File

@ -208,6 +208,13 @@ class Conversation extends Model
*/
protected $guarded = ['id', 'folder_id'];
/**
* Convert to array.
*/
protected $casts = [
'meta' => 'array',
];
/**
* Default values.
*/
@ -499,6 +506,11 @@ class Conversation extends Model
return $this->status == self::STATUS_SPAM;
}
public function isClosed()
{
return $this->status == self::STATUS_CLOSED;
}
/**
* Get status name.
*
@ -2235,55 +2247,29 @@ class Conversation extends Model
}
}
// /**
// * Get conversation meta data as array.
// */
// public function getMetas()
// {
// return \Helper::jsonToArray($this->meta);
// }
/**
* Get meta value.
*/
public function getMeta($key, $default = null)
{
if (isset($this->meta[$key])) {
return $this->meta[$key];
} else {
return $default;
}
}
// /**
// * Set conversation meta value.
// */
// public function setMetas($data)
// {
// $this->meta = json_encode($data);
// }
/**
* Set meta value.
*/
public function setMeta($key, $value, $save = false)
{
$meta = $this->meta;
$meta[$key] = $value;
$this->meta = $meta;
// /**
// * Get conversation meta value.
// */
// public function getMeta($key, $default = null)
// {
// $metas = $this->getMetas();
// if (isset($metas[$key])) {
// return $metas[$key];
// } else {
// return $default;
// }
// }
// /**
// * Set conversation meta value.
// */
// public function setMeta($key, $value)
// {
// $metas = $this->getMetas();
// $metas[$key] = $value;
// $this->setMetas($metas);
// }
// /**
// * Create new conversation.
// */
// public static function create($data = [], $save = true)
// {
// $conversation = new Conversation();
// $conversation->fill($data);
// if ($save) {
// $conversation->save();
// }
// }
if ($save) {
$this->save();
}
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddMetaColumnToConversationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('conversations', function (Blueprint $table) {
// Meta data in JSON format.
$table->text('meta')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('customers', function (Blueprint $table) {
$table->dropColumn('meta');
});
}
}