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)' );
 }
Esempio n. 2
0
 /**
  * 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);
 }
Esempio n. 3
0
 /**
  * drop an existing table
  *
  * @param string $name name of the table that should be dropped
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function dropTable($name)
 {
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $db->beginNestedTransaction();
     $result = $this->_dropAutoincrement($name);
     if (!PEAR::isError($result)) {
         $result = parent::dropTable($name);
     }
     $db->completeNestedTransaction();
     return $result;
 }
Esempio n. 4
0
 /**
  * drop an existing table
  *
  * @param string $name name of the table that should be dropped
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function dropTable($name)
 {
     $db = $this->getDBInstance();
     if (MDB2::isError($db)) {
         return $db;
     }
     //delete the triggers associated to existing FK constraints
     $constraints = $this->listTableConstraints($name);
     if (!MDB2::isError($constraints) && !empty($constraints)) {
         $db->loadModule('Reverse', null, true);
         foreach ($constraints as $constraint) {
             $definition = $db->reverse->getTableConstraintDefinition($name, $constraint);
             if (!MDB2::isError($definition) && !empty($definition['foreign'])) {
                 $result = $this->_dropFKTriggers($name, $constraint, $definition['references']['table']);
                 if (MDB2::isError($result)) {
                     return $result;
                 }
             }
         }
     }
     return parent::dropTable($name);
 }
 /**
  * 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;
 }
Esempio n. 6
0
 /**
  * drop existing constraint
  *
  * @param string $table   name of table that should be used in method
  * @param string $name    name of the constraint to be dropped
  * @param string $primary hint if the constraint is primary
  *
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function dropConstraint($table, $name, $primary = false)
 {
     $db = $this->getDBInstance();
     if (MDB2::isError($db)) {
         return $db;
     }
     // is it an UNIQUE index?
     $query = 'SELECT relname
                 FROM pg_class
                WHERE oid IN (
                      SELECT indexrelid
                        FROM pg_index, pg_class
                       WHERE pg_class.relname = ' . $db->quote($table, 'text') . '
                         AND pg_class.oid = pg_index.indrelid
                         AND indisunique = \'t\')
               EXCEPT
               SELECT conname
                FROM pg_constraint, pg_class
               WHERE pg_constraint.conrelid = pg_class.oid
                 AND relname = ' . $db->quote($table, 'text');
     $unique = $db->queryCol($query, 'text');
     if (MDB2::isError($unique) || empty($unique)) {
         // not an UNIQUE index, maybe a CONSTRAINT
         return parent::dropConstraint($table, $name, $primary);
     }
     if (in_array($name, $unique)) {
         $result = $db->exec('DROP INDEX ' . $db->quoteIdentifier($name, true));
         if (MDB2::isError($result)) {
             return $result;
         }
         return MDB2_OK;
     }
     $idxname = $db->getIndexName($name);
     if (in_array($idxname, $unique)) {
         $result = $db->exec('DROP INDEX ' . $db->quoteIdentifier($idxname, true));
         if (MDB2::isError($result)) {
             return $result;
         }
         return MDB2_OK;
     }
     return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, $name . ' is not an existing constraint for table ' . $table, __FUNCTION__);
 }
Esempio n. 7
0
 /**
  * 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);
 }
Esempio n. 8
0
 /**
  * drop existing constraint
  *
  * @param string    $table        name of table that should be used in method
  * @param string    $name         name of the constraint to be dropped
  * @param string    $primary      hint if the constraint is primary
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function dropConstraint($table, $name, $primary = false)
 {
     $db = $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     //is it a FK constraint? If so, also delete the associated triggers
     $db->loadModule('Reverse', null, true);
     $definition = $db->reverse->getTableConstraintDefinition($table, $name);
     if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
         //first drop the FK enforcing triggers
         $result = $this->_dropFKTriggers($table, $name, $definition['references']['table']);
         if (PEAR::isError($result)) {
             return $result;
         }
     }
     return parent::dropConstraint($table, $name, $primary);
 }
Esempio n. 9
0
 /**
  * drop an existing table
  *
  * @param string $name name of the table that should be dropped
  *
  * @return mixed MDB2_OK on success, a MDB2 error on failure
  * @access public
  */
 function dropTable($name)
 {
     $result = $this->_dropAutoincrement($name);
     if (MDB2::isError($result)) {
         return $result;
     }
     $result = parent::dropTable($name);
     if (MDB2::isError($result)) {
         return $result;
     }
     $this->_silentCommit();
     return $result;
 }