function install(array $arrPlugin, SC_Plugin_Installer $installer)
 {
     $plugin_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
     $upload_plugin_dir = PLUGIN_UPLOAD_REALDIR . $arrPlugin["plugin_code"] . DIRECTORY_SEPARATOR;
     $backup_plugin_dir = PLUGIN_UPLOAD_REALDIR . $arrPlugin["plugin_code"] . "_" . date("Ymd") . DIRECTORY_SEPARATOR;
     if (!is_dir($backup_plugin_dir)) {
         SC_Utils_Ex::sfCopyDir($upload_plugin_dir, $backup_plugin_dir);
     }
     SC_Helper_FileManager_Ex::deleteFile($upload_plugin_dir, false);
     SC_Utils_Ex::sfCopyDir($plugin_dir . "/", $upload_plugin_dir);
     SC_Utils_Ex::sfCopyDir($plugin_dir . "/copy/Smarty/templates/admin/", TEMPLATE_ADMIN_REALDIR);
     SC_Utils_Ex::sfCopyDir($plugin_dir . "/copy/modules/", DATA_REALDIR . "module/");
     // logo コピー
     $installer->copyDirectory("copy/plugin_dir/", "");
     $table = "dtb_products";
     $fields = array('auto_display_status' => $this->intColumn('自動公開'), 'auto_display_start_date' => $this->timestampColumn('公開開始日'), 'auto_display_end_date' => $this->timestampColumn('公開終了日'));
     $type = "timestamp";
     $definition = compact("type");
     foreach ($fields as $name => $define) {
         $this->objDb->sfColumnExists($table, $name, $define["type"], "", true);
         $this->fieldComment($installer, $table, $name, $define["comment"]);
         switch ($define["type"]) {
             case "timestamp":
                 break;
             default:
                 continue;
         }
         $change = array();
         $change[$name] = compact('definition');
         $this->objManager->alterTable($table, compact("change"), false);
     }
     $this->objQuery->update("dtb_products", array(), "auto_display_start_date IS NULL", array(), array("auto_display_start_date" => "create_date"));
     $masterfields = array("id" => $this->intColumn("ID"), "name" => $this->textColumn("NAME"), "rank" => $this->intColumn("RANK"));
     $table = "atd_mtb_auto_display_status";
     if ($this->objDb->sfColumnExists($table, "id") == false) {
         $this->objManager->createTable($table, $masterfields);
     }
     foreach ($masterfields as $name => $define) {
         $this->objDb->sfColumnExists($table, $name, $define["type"], "", true);
         $this->fieldComment($installer, $table, $name, $define["comment"]);
     }
     $this->masterdata->deleteMasterData($table);
     $this->masterdata->clearCache($table);
     $this->masterdata->registMasterData($table, array(), explode(",", "常時公開,時限公開"));
     // $this->insertMasterData ( "PRODUCTS_RESULT_ROWSPAN", 1, '管理画面/商品管理一覧 行結合数' );
     // $this->insertMasterData ( "PRODUCTS_RESULT_COLUMN", 5, '管理画面/商品管理一覧 列位置' );
     // $this->insertMasterData ( "PRODUCTS_SEARCH_AUTO_DISPLAY", 1, '検索画面表示設定(1: ON/ 0:OFF)' );
     // $this->insertMasterData ( "PRODUCTS_DETAIL_AUTO_DISPLAY", 1, '検索画面表示設定(1: ON/ 0:OFF)' );
 }
示例#2
0
文件: mssql.php 项目: Dulciane/jaws
 /**
  * create a new table
  *
  * @param string $name   Name of the database that should be created
  * @param array  $fields Associative array that contains the definition of each field of the new table
  *                       The indexes of the array entries are the names of the fields of the table an
  *                       the array entry values are associative arrays like those that are meant to be
  *                       passed with the field definitions to get[Type]Declaration() functions.
  *
  *                      Example
  *                        array(
  *
  *                            'id' => array(
  *                                'type' => 'integer',
  *                                'unsigned' => 1,
  *                                'notnull' => 1,
  *                                'default' => 0,
  *                            ),
  *                            'name' => array(
  *                                'type' => 'text',
  *                                'length' => 12,
  *                            ),
  *                            'description' => array(
  *                                'type' => 'text',
  *                                'length' => 12,
  *                            )
  *                        );
  * @param array $options An associative array of table options:
  *                          array(
  *                              'comment' => 'Foo',
  *                              'temporary' => true|false,
  *                          );
  *
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function createTable($name, $fields, $options = array())
 {
     if (!empty($options['temporary'])) {
         $name = '#' . $name;
     }
     return parent::createTable($name, $fields, $options);
 }
示例#3
0
文件: oci8.php 项目: arlendotcn/ilias
 /**
  * create a new table
  *
  * @param string $name     Name of the database that should be created
  * @param array $fields Associative array that contains the definition of each field of the new table
  *                        The indexes of the array entries are the names of the fields of the table an
  *                        the array entry values are associative arrays like those that are meant to be
  *                         passed with the field definitions to get[Type]Declaration() functions.
  *
  *                        Example
  *                        array(
  *
  *                            'id' => array(
  *                                'type' => 'integer',
  *                                'unsigned' => 1
  *                                'notnull' => 1
  *                                'default' => 0
  *                            ),
  *                            'name' => array(
  *                                'type' => 'text',
  *                                'length' => 12
  *                            ),
  *                            'password' => array(
  *                                'type' => 'text',
  *                                'length' => 12
  *                            )
  *                        );
  * @param array $options  An associative array of table options:
  *                          array(
  *                              'comment' => 'Foo',
  *                              'temporary' => true|false,
  *                          );
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function createTable($name, $fields, $options = array())
 {
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $db->beginNestedTransaction();
     $result = parent::createTable($name, $fields, $options);
     if (!PEAR::isError($result)) {
         foreach ($fields as $field_name => $field) {
             if (!empty($field['autoincrement'])) {
                 $result = $this->_makeAutoincrement($field_name, $name);
             }
         }
     }
     $db->completeNestedTransaction();
     return $result;
 }
 /**
  * create a new table
  *
  * @param string $name    Name of the database that should be created
  * @param array  $fields  Associative array that contains the definition
  *                        of each field of the new table
  * @param array  $options An associative array of table options
  *
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function createTable($name, $fields, $options = array())
 {
     $result = parent::createTable($name, $fields, $options);
     if (PEAR::isError($result)) {
         return $result;
     }
     // create triggers to enforce FOREIGN KEY constraints
     if (!empty($options['foreign_keys'])) {
         $db = $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }
         foreach ($options['foreign_keys'] as $fkname => $fkdef) {
             if (empty($fkdef)) {
                 continue;
             }
             //set actions to default if not set
             $fkdef['onupdate'] = empty($fkdef['onupdate']) ? $db->options['default_fk_action_onupdate'] : strtoupper($fkdef['onupdate']);
             $fkdef['ondelete'] = empty($fkdef['ondelete']) ? $db->options['default_fk_action_ondelete'] : strtoupper($fkdef['ondelete']);
             $trigger_names = array('insert' => $fkname . '_insert_trg', 'update' => $fkname . '_update_trg', 'pk_update' => $fkname . '_pk_update_trg', 'pk_delete' => $fkname . '_pk_delete_trg');
             //create the [insert|update] triggers on the FK table
             $table_fields = array_keys($fkdef['fields']);
             $referenced_fields = array_keys($fkdef['references']['fields']);
             $query = 'CREATE TRIGGER %s BEFORE %s ON ' . $name . ' FOR EACH ROW BEGIN' . ' SELECT RAISE(ROLLBACK, \'%s on table "' . $name . '" violates FOREIGN KEY constraint "' . $fkname . '"\')' . ' WHERE  (SELECT ';
             $aliased_fields = array();
             foreach ($referenced_fields as $field) {
                 $aliased_fields[] = $fkdef['references']['table'] . '.' . $field . ' AS ' . $field;
             }
             $query .= implode(',', $aliased_fields) . ' FROM ' . $fkdef['references']['table'] . ' WHERE ';
             $conditions = array();
             for ($i = 0; $i < count($table_fields); $i++) {
                 $conditions[] = $referenced_fields[$i] . ' = NEW.' . $table_fields[$i];
             }
             $query .= implode(' AND ', $conditions) . ') IS NULL; END;';
             $result = $db->exec(sprintf($query, $trigger_names['insert'], 'INSERT', 'insert'));
             if (PEAR::isError($result)) {
                 return $result;
             }
             $result = $db->exec(sprintf($query, $trigger_names['update'], 'UPDATE', 'update'));
             if (PEAR::isError($result)) {
                 return $result;
             }
             //create the ON [UPDATE|DELETE] triggers on the primary table
             $restrict_action = 'SELECT RAISE(ROLLBACK, \'%s on table "' . $name . '" violates FOREIGN KEY constraint "' . $fkname . '"\')' . ' WHERE  (SELECT ';
             $aliased_fields = array();
             foreach ($table_fields as $field) {
                 $aliased_fields[] = $name . '.' . $field . ' AS ' . $field;
             }
             $restrict_action .= implode(',', $aliased_fields) . ' FROM ' . $name . ' WHERE ';
             $conditions = array();
             $new_values = array();
             $null_values = array();
             for ($i = 0; $i < count($table_fields); $i++) {
                 $conditions[] = $table_fields[$i] . ' = OLD.' . $referenced_fields[$i];
                 $new_values[] = $table_fields[$i] . ' = NEW.' . $referenced_fields[$i];
                 $null_values[] = $table_fields[$i] . ' = NULL';
             }
             $conditions2 = array();
             for ($i = 0; $i < count($referenced_fields); $i++) {
                 $conditions2[] = 'NEW.' . $referenced_fields[$i] . ' <> OLD.' . $referenced_fields[$i];
             }
             $restrict_action .= implode(' AND ', $conditions) . ') IS NOT NULL' . ' AND (' . implode(' OR ', $conditions2) . ')';
             $cascade_action_update = 'UPDATE ' . $name . ' SET ' . implode(', ', $new_values) . ' WHERE ' . implode(' AND ', $conditions);
             $cascade_action_delete = 'DELETE FROM ' . $name . ' WHERE ' . implode(' AND ', $conditions);
             $setnull_action = 'UPDATE ' . $name . ' SET ' . implode(', ', $null_values) . ' WHERE ' . implode(' AND ', $conditions);
             if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) {
                 $db->loadModule('Reverse', null, true);
                 $default_values = array();
                 foreach ($table_fields as $table_field) {
                     $field_definition = $db->reverse->getTableFieldDefinition($name, $field);
                     if (PEAR::isError($field_definition)) {
                         return $field_definition;
                     }
                     $default_values[] = $table_field . ' = ' . $field_definition[0]['default'];
                 }
                 $setdefault_action = 'UPDATE ' . $name . ' SET ' . implode(', ', $default_values) . ' WHERE ' . implode(' AND ', $conditions);
             }
             $query = 'CREATE TRIGGER %s' . ' %s ON ' . $fkdef['references']['table'] . ' FOR EACH ROW BEGIN ';
             if ('CASCADE' == $fkdef['onupdate']) {
                 $sql_update = sprintf($query, $trigger_names['pk_update'], 'AFTER UPDATE', 'update') . $cascade_action_update . '; END;';
             } elseif ('SET NULL' == $fkdef['onupdate']) {
                 $sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setnull_action . '; END;';
             } elseif ('SET DEFAULT' == $fkdef['onupdate']) {
                 $sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setdefault_action . '; END;';
             } elseif ('NO ACTION' == $fkdef['onupdate']) {
                 $sql_update = sprintf($query . $restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update') . '; END;';
             } elseif ('RESTRICT' == $fkdef['onupdate']) {
                 $sql_update = sprintf($query . $restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . '; END;';
             }
             if ('CASCADE' == $fkdef['ondelete']) {
                 $sql_delete = sprintf($query, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete') . $cascade_action_delete . '; END;';
             } elseif ('SET NULL' == $fkdef['ondelete']) {
                 $sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setnull_action . '; END;';
             } elseif ('SET DEFAULT' == $fkdef['ondelete']) {
                 $sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setdefault_action . '; END;';
             } elseif ('NO ACTION' == $fkdef['ondelete']) {
                 $sql_delete = sprintf($query . $restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete') . '; END;';
             } elseif ('RESTRICT' == $fkdef['ondelete']) {
                 $sql_delete = sprintf($query . $restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . '; END;';
             }
             if (PEAR::isError($result)) {
                 return $result;
             }
             $result = $db->exec($sql_delete);
             if (PEAR::isError($result)) {
                 return $result;
             }
             $result = $db->exec($sql_update);
             if (PEAR::isError($result)) {
                 return $result;
             }
         }
     }
     if (PEAR::isError($result)) {
         return $result;
     }
     return MDB2_OK;
 }
示例#5
0
文件: sqlsrv.php 项目: Dulciane/jaws
 /**
  * create a new table
  *
  * @param string $name   Name of the database that should be created
  * @param array  $fields Associative array that contains the definition of each field of the new table
  *                       The indexes of the array entries are the names of the fields of the table an
  *                       the array entry values are associative arrays like those that are meant to be
  *                       passed with the field definitions to get[Type]Declaration() functions.
  *
  *                      Example
  *                        array(
  *
  *                            'id' => array(
  *                                'type' => 'integer',
  *                                'unsigned' => 1,
  *                                'notnull' => 1,
  *                                'default' => 0,
  *                            ),
  *                            'name' => array(
  *                                'type' => 'text',
  *                                'length' => 12,
  *                            ),
  *                            'description' => array(
  *                                'type' => 'text',
  *                                'length' => 12,
  *                            )
  *                        );
  * @param array $options An associative array of table options:
  *                          array(
  *                              'comment' => 'Foo',
  *                              'temporary' => true|false,
  *                          );
  *
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function createTable($name, $fields, $options = array())
 {
     /*if (!empty($options['temporary'])) {
           $name = '#'.$name;//would make subsequent calls fail because it would go out ot scope and be destroyed already
       }*/
     return parent::createTable($name, $fields, $options);
 }