| @@ -16,8 +16,31 @@ | ||
| 16 | 16 | static::$_emailTemplateModel = new EmailTemplateModel(); |
| 17 | 17 | $this->_user_details = $user_details; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + /** | |
| 21 | + * Decode a stored template `config` column into the object shape the admin editor expects. | |
| 22 | + * | |
| 23 | + * Older versions could persist an empty config as `[]`; decoded, that reaches the React editor | |
| 24 | + * as a JS array and setting a key on it throws inside the immutable-draft library. Anything that | |
| 25 | + * is not a non-empty object collapses to `{}`. | |
| 26 | + * | |
| 27 | + * @param mixed $config raw column value (JSON string, already-decoded value, or null) | |
| 28 | + * | |
| 29 | + * @return object | |
| 30 | + */ | |
| 31 | + public static function normalizeConfig($config) | |
| 32 | + { | |
| 33 | + if (is_string($config)) { | |
| 34 | + $config = json_decode($config); | |
| 35 | + } | |
| 36 | + if (is_array($config)) { | |
| 37 | + $config = (object) $config; | |
| 38 | + } | |
| 39 | + | |
| 40 | + return is_object($config) ? $config : (object) []; | |
| 41 | + } | |
| 42 | + | |
| 20 | 43 | public function getAllTemplate($templateID = null, $userID = null) |
| 21 | 44 | { |
| 22 | 45 | $condition = [ |
| 23 | 46 | 'form_id' => static::$_formID, |
| @@ -32,9 +55,11 @@ | ||
| 32 | 55 | [ |
| 33 | 56 | 'id', |
| 34 | 57 | 'title', |
| 35 | 58 | 'sub', |
| 36 | - 'body' | |
| 59 | + 'body', | |
| 60 | + 'status', | |
| 61 | + 'config' | |
| 37 | 62 | ], |
| 38 | 63 | $condition |
| 39 | 64 | ); |
| 40 | 65 | } |
| @@ -50,8 +75,10 @@ | ||
| 50 | 75 | [ |
| 51 | 76 | 'title' => $templateDetail->title, |
| 52 | 77 | 'sub' => $templateDetail->sub, |
| 53 | 78 | 'body' => $templateDetail->body, |
| 79 | + 'status' => isset($templateDetail->status) ? (int) $templateDetail->status : 1, | |
| 80 | + 'config' => isset($templateDetail->config) ? wp_json_encode($templateDetail->config) : null, | |
| 54 | 81 | 'form_id' => static::$_formID, |
| 55 | 82 | 'user_id' => $this->_user_details['id'], |
| 56 | 83 | 'user_ip' => $this->_user_details['ip'], |
| 57 | 84 | 'created_at'=> $this->_user_details['time'], |
| @@ -66,8 +93,10 @@ | ||
| 66 | 93 | [ |
| 67 | 94 | 'title' => $templateDetail->title, |
| 68 | 95 | 'sub' => $templateDetail->sub, |
| 69 | 96 | 'body' => $templateDetail->body, |
| 97 | + 'status' => isset($templateDetail->status) ? (int) $templateDetail->status : 1, | |
| 98 | + 'config' => isset($templateDetail->config) ? wp_json_encode($templateDetail->config) : null, | |
| 70 | 99 | 'form_id' => static::$_formID, |
| 71 | 100 | 'user_id' => $this->_user_details['id'], |
| 72 | 101 | 'user_ip' => $this->_user_details['ip'], |
| 73 | 102 | 'updated_at'=> $this->_user_details['time'] |