public function discover($entity, $flavor = array()) { $ckey = $this->cache_key($entity); if ($this->enable_cache && $this->cache()->has($ckey)) { return $this->cache()->get($ckey); } $data = $entity->mapper ? $entity->mapper->schema_fields() : null; if (!empty($data) && !$this->force_inspect) { $data = CMS_Fields::fields_to_schema($data, $entity->mapper->options['table'][0]); } else { $data = $entity->mapper ? $entity->mapper->inspect() : null; } if (!empty($data)) { $res = $this->from_schema($data); if ($this->enable_cache) { $this->cache()->set($ckey, $res, 0); } return $res; } }
public function process_schema() { // process schema modules $modules = $this->schema_modules(); if (!empty($modules)) { foreach ($modules as $name => $module) { CMS::cached_run($module); } } // get data from config $schema = $this->config('schema'); $fields = $this->config('fields'); $tmp1 = (array) $schema; $tmp2 = (array) $fields; if (empty($tmp1) && empty($tmp2)) { return; } if (empty($fields)) { $fields = Core::hash(); } $schema = clone $schema; // some time we have fields without info in schema // fix it $schema_keys = array_keys((array) $schema); $fields_keys = array_keys((array) $fields); $diff = array_diff($fields_keys, $schema_keys); foreach ($diff as $name) { $schema->{$name} = array(); } //fields to schema Core::load('DB.Schema'); Core::load('CMS.Fields'); foreach ($schema as $name => &$table) { if (!empty($fields->{$name})) { $table_fields = $fields->{$name}; $table_name = $name; CMS_Fields::fields_to_schema($fields->{$name}, $name, $table); Events::add_once('db.schema.after_execute.' . $name, function ($tf_schema) use($table_fields, $table_name) { foreach ($table_fields as $tf_name => $tf_data) { $tf_type = CMS_Fields::type($tf_data); $tf_type->process_schema($tf_name, $tf_data, $table_name, $table_fields); } }); } } // remove empty values foreach ($schema as $name => $ttable) { if (empty($ttable)) { unset($schema->{$name}); } } // cache $cname = strtolower($this->get_name()); if (!empty($cname)) { $cache_key = 'cms:component:' . $cname . ':schema:' . md5(serialize($schema)); if ($this->cache->has($cache_key)) { return $this; } $this->cache->set($cache_key, 1, 0); } // run DB_Schema::process_cache($schema); }
public function schema() { $schema = CMS_Fields::fields_to_schema($this->fields_data); $name = $this->__name(); $component = $this->component(); $data = $component && $component->config('schema') && isset($component->config('schema')->{$name}) ? $component->config('schema')->{$name} : array(); return $data ? array_replace_recursive($data, $schema) : $schema; }