] = '%s'; return $data; } /** * Get update data and formats, can be overridden by child classes * * @return array{data:array,formats:string[]} */ protected function getUpdateData(): array { $data = parent::getUpdateData(); $data['data']['type'] = static::getType(); $data['data']['data'] = JsonSerialize::serialize($this, JsonSerialize::JSON_SKIP_CLASS_NAME | JSON_PRETTY_PRINT); $data['value_1'] = $this->value1; $data['value_2'] = $this->value2; $data['value_3'] = $this->value3; $data['value_4'] = $this->value4; $data['value_5'] = $this->value5; $data['formats'][] = '%s'; $data['formats'][] = '%s'; $data['formats'][] = '%s'; $data['formats'][] = '%s'; $data['formats'][] = '%s'; $data['formats'][] = '%s'; $data['formats'][] = '%s'; return $data; } /** * Entity table name * * @param bool $escape If true apply esc_sql to table name * * @return string */ final public static function getTableName(bool $escape = false): string { /** @var wpdb $wpdb */ global $wpdb; $res = $wpdb->base_prefix . 'duplicator_entities'; return ($escape ? esc_sql($res) : $res); } /** * Get where clause for get from database, can be overridden by child classes * * @return string */ protected static function getWhereClause(): string { /** @var wpdb $wpdb */ global $wpdb; return $wpdb->prepare('type = %s', static::getType()); } /** * Get Model from database row * * @param array $row Database row * * @return static */ protected static function getModelFromRow(array $row) { return static::getEntityFromJson($row['data'], $row); } /** * Init entity table * * @return string[] Strings containing the results of the various update queries. */ final public static function initTable(): array { /** @var wpdb $wpdb */ global $wpdb; $charset_collate = $wpdb->get_charset_collate(); $table_name = static::getTableName(true); // PRIMARY KEY must have 2 spaces before for dbDelta to work // Mysql 5.5 can't have more than 1 DEFAULT CURRENT_TIMESTAMP $sql = <<