protected function up()
 {
     $content_com = fx::component('floxim.main.content');
     fx::db()->query(array('insert into {{field}} (
                 `component_id` ,
                 `keyword` ,
                 `name_en` ,
                 `name_ru` ,
                 `type`)
               VALUES (%d, "type", "Type", "Тип", 1)', $content_com['id']));
     fx::cache('meta')->flush();
 }
Ejemplo n.º 2
0
 public function GET_POST($item = "")
 {
     if (empty($this->_GET) && empty($this->_POST)) {
         return array();
     }
     if ($item) {
         return array_key_exists($item, $this->_GET) ? fx::db()->escape($this->_GET[$item]) : (array_key_exists($item, $this->_POST) ? fx::db()->escape($this->_POST[$item]) : null);
     }
     $data = array_merge($this->_POST, $this->_GET);
     foreach ($data as $k => &$v) {
         $v = fx::db()->escape($v);
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Удаляет из временной таблицы текущие данные
  *
  * @throws \Exception
  */
 protected function removeDataFromTmpTable()
 {
     if ($this->key) {
         fx::db()->query("delete from {{" . $this->tmpTable . "}} where `key` = '{$this->key}'");
     }
 }
Ejemplo n.º 4
0
 /**
  * Get database schema
  * @param type $table
  */
 public static function schema($table = null)
 {
     static $schema = null;
     if (is_null($schema)) {
         $schema = fx::db()->getSchema();
     }
     if (func_num_args() === 0) {
         return $schema;
     }
     if (isset($schema[$table])) {
         return $schema[$table];
     }
 }
Ejemplo n.º 5
0
 /**
  * 
  */
 public function dumpSiteData($site_id = null, $target_file = null)
 {
     if (is_null($site_id)) {
         $site_id = fx::env('site_id');
     }
     if (is_null($target_file)) {
         $dir = '@files/export/site_' . $site_id;
         fx::files()->mkdir($dir);
         $target_file = fx::path()->abs($dir . '/data.sql');
     }
     // export the site
     fx::db()->dump(array('tables' => array('site'), 'where' => 'id = ' . $site_id, 'schema' => false, 'file' => $target_file));
     // export infoblocks
     fx::db()->dump(array('tables' => array('infoblock'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // export URL aliases
     fx::db()->dump(array('tables' => array('url_alias'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // export infoblock_visual
     $infoblock_ids = fx::data('infoblock')->where('site_id', $site_id)->all()->getValues('id');
     fx::db()->dump(array('tables' => array('infoblock_visual'), 'where' => 'infoblock_id IN (' . join(", ", $infoblock_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true));
     // export main content table
     fx::db()->dump(array('tables' => array('floxim_main_content'), 'where' => 'site_id  = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true));
     // get existing content items
     $items = fx::db()->getResults('select id, type from {{floxim_main_content}} where site_id = ' . $site_id);
     $tables = $this->getContentDumpTables(fx::collection($items));
     foreach ($tables as $t => $item_ids) {
         if ($t === 'floxim_main_content') {
             continue;
         }
         // export content table
         fx::db()->dump(array('tables' => array($t), 'where' => 'id IN (' . join(',', $item_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true));
     }
 }
Ejemplo n.º 6
0
 protected function up()
 {
     fx::db()->query("\n            INSERT INTO {{option}} (`id`, `keyword`, `name`, `value`, `autoload`) VALUES (NULL, 'fx.version', 'Current floxim version', '0.1.1', '1');\n        ");
 }
Ejemplo n.º 7
0
 protected function setStatement($data)
 {
     $cols = $this->getColumns();
     $set = array();
     $encoded_fields = $this->getNonScalarFields();
     foreach ($data as $k => $v) {
         if (!in_array($k, $cols)) {
             continue;
         }
         if (in_array($k, $this->serialized)) {
             $v = serialize($v);
         }
         if (in_array($k, $encoded_fields)) {
             $v = json_encode($v);
         }
         $str = "'" . fx::db()->escape($v) . "' ";
         if (isset($this->sql_function[$k])) {
             $str = $this->sql_function[$k] . "(" . $str . ")";
         }
         $set[] = "`" . fx::db()->escape($k) . "` = " . $str;
     }
     return $set;
 }
 protected function up()
 {
     // create table
     fx::db()->query("\n            CREATE TABLE IF NOT EXISTS {{option}} (\n              `id` int(11) NOT NULL AUTO_INCREMENT,\n              `keyword` varchar(255) NOT NULL,\n              `name` varchar(255) NOT NULL,\n              `value` text NOT NULL,\n              `autoload` tinyint(1) NOT NULL DEFAULT '1',\n              PRIMARY KEY (`id`),\n              KEY `autoload` (`autoload`),\n              KEY `keyword` (`keyword`)\n            ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;\n        ");
 }