コード例 #1
0
 public function action_update()
 {
     $name = $this->request->param('id');
     $field = new Model_UserField();
     $field_data = $field->get($name);
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $name));
     $this->template->title = __('Edit Custom Field for Advertisement');
     if ($_POST) {
         try {
             $options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE, 'show_profile' => Core::post('show_profile') == 'on' ? TRUE : FALSE, 'show_register' => Core::post('show_register') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE);
             if ($field->update($name, Core::post('values'), $options)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s edited'), $name));
             } else {
                 Alert::set(Alert::ERROR, sprintf(__('Field %s cannot be edited'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'userfields', 'action' => 'index')));
     }
     $this->template->content = View::factory('oc-panel/pages/userfields/update', array('field_data' => $field_data, 'name' => $name));
 }
コード例 #2
0
ファイル: update.php プロジェクト: johnulist/openclassifieds2
 /**
  * This function will upgrade DB that didn't existed in versions prior to 2.5.1
  */
 public function action_251()
 {
     //CF users searchable admin privilege option to false if didnt exists
     $cf_users = Model_UserField::get_all();
     foreach ($cf_users as $name => $options) {
         $modified = FALSE;
         if (!isset($options['searchable'])) {
             $options['searchable'] = FALSE;
             $modified = TRUE;
         }
         if (!isset($options['admin_privilege'])) {
             $options['admin_privilege'] = FALSE;
             $modified = TRUE;
         }
         if ($modified === TRUE) {
             $field = new Model_UserField();
             $field->update($name, $options['values'] ? implode(',', $options['values']) : null, $options);
         }
     }
     //change latitude/longitude data type length
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "ads` CHANGE `latitude` `latitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "ads` CHANGE `longitude` `longitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "locations` CHANGE `latitude` `latitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "locations` CHANGE `longitude` `longitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     // set to NULL latitude and longitude ads with longitude and longitude equal to 0
     try {
         DB::query(Database::UPDATE, "UPDATE " . self::$db_prefix . "ads SET latitude=NULL, longitude=NULL WHERE latitude='0' AND longitude='0'")->execute();
     } catch (exception $e) {
     }
     //messages status
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "messages` ADD `status_to` tinyint(1) NOT NULL DEFAULT '0'")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "messages` ADD `status_from` tinyint(1) NOT NULL DEFAULT '0'")->execute();
     } catch (exception $e) {
     }
     //do something with status to migrate to status_from
     try {
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "messages` SET `status_from`=`status` , `status_to`=`status`")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "messages` DROP `status`")->execute();
     } catch (exception $e) {
     }
     //new configs
     $configs = array(array('config_key' => 'measurement', 'group_name' => 'general', 'config_value' => 'metric'), array('config_key' => 'leave_alert', 'group_name' => 'advertisement', 'config_value' => '1'));
     Model_Config::config_array($configs);
 }