Gets column information from a table
public static get_table_columns ( string $table ) : array | ||
$table | string | Table Name |
return | array |
/** * @param $params * * @return array|bool|int|mixed|null|void */ public function prepare_pod($params) { /** * @var $wpdb WPDB */ global $wpdb; if (!isset($params->pod)) { return pods_error(__('Invalid Pod.', 'pods')); } $pod = pods_sanitize(pods_clean_name($params->pod)); if (!in_array("{$wpdb->prefix}pod_tbl_{$pod}", $this->tables)) { return pods_error(__('Table not found, it cannot be migrated', 'pods')); } $count = pods_query("SELECT COUNT(*) AS `count` FROM `@wp_pod_tbl_{$pod}`", false); if (!empty($count)) { $count = (int) $count[0]->count; } else { $count = 0; } $pod_type = pods_query("SELECT `id` FROM `@wp_pod_types` WHERE `name` = '{$pod}'", false); if (!empty($pod_type)) { $pod_type = (int) $pod_type[0]->id; } else { return pods_error(__('Pod not found, it cannot be migrated', 'pods')); } $fields = array('id'); $field_rows = pods_query("SELECT `id`, `name`, `coltype` FROM `@wp_pod_fields` WHERE `datatype` = {$pod_type} ORDER BY `weight`, `name`"); if (!empty($field_rows)) { foreach ($field_rows as $field) { if (!in_array($field->coltype, array('pick', 'file'))) { $fields[] = $field->name; } } } $columns = PodsData::get_table_columns("{$wpdb->prefix}pod_tbl_{$pod}"); $errors = array(); foreach ($columns as $column => $info) { if (!in_array($column, $fields)) { $errors[] = "<strong>{$column}</strong> " . __('is a field in the table, but was not found in this pod - the field data will not be migrated.', 'pods'); } } foreach ($fields as $field) { if (!isset($columns[$field])) { $errors[] = "<strong>{$field}</strong> " . __('is a field in this pod, but was not found in the table - the field data will not be migrated.', 'pods'); } } if (!empty($errors)) { return pods_error(implode('<br />', $errors)); } return $count; }