update() 공개 메소드

When updating a theme, run the attributes through a validator first.
public update ( array $attributes = [], array $options = [] ) : void
$attributes array
$options array
리턴 void
예제 #1
0
 public function processUpdate()
 {
     if (Tools::getIsset('id_theme') && Tools::getIsset('name') && Tools::getIsset('directory')) {
         $theme = new Theme((int) Tools::getValue('id_theme'));
         $theme->name = Tools::getValue('name');
         $theme->directory = Tools::getValue('directory');
         $theme->default_left_column = Tools::getValue('default_left_column');
         $theme->default_right_column = Tools::getValue('default_right_column');
         $nb_product_per_page = (int) Tools::getValue('product_per_page');
         if ($nb_product_per_page == 0) {
             $nb_product_per_page = 1;
         }
         $theme->product_per_page = $nb_product_per_page;
         if ($this->context->shop->id_theme == (int) Tools::getValue('id_theme')) {
             Configuration::updateValue('PS_PRODUCTS_PER_PAGE', $nb_product_per_page);
         }
         if (isset($_FILES['image_preview']) && $_FILES['image_preview']['error'] == 0) {
             if (@getimagesize($_FILES['image_preview']['tmp_name']) && !ImageManager::validateUpload($_FILES['image_preview'], 300000)) {
                 move_uploaded_file($_FILES['image_preview']['tmp_name'], _PS_ALL_THEMES_DIR_ . $theme->directory . '/preview.jpg');
             } else {
                 $this->errors[] = $this->l('Image not valid');
                 $this->display = 'form';
                 return false;
             }
         }
         $theme->update();
     }
     Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminThemes') . '&conf=29');
 }
예제 #2
0
 public function executeUpdate($request)
 {
     $this->prepareUpdate();
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter('theme'), $request->getFiles('theme'));
         if ($this->form->isValid()) {
             $theme = Theme::update($this->form->getValues(), $this->getUser()->getUser());
             $this->redirect('/theme/read?id=' . $theme->getId());
         }
     }
 }
예제 #3
0
 public function processApplyConfigs()
 {
     $id_theme = Context::getContext()->shop->id_theme;
     $theme_name = Context::getContext()->shop->theme_name;
     $data = simplexml_load_file(_PS_ALL_THEMES_DIR_ . $theme_name . '/samples/themeconfig.xml');
     if (!$data) {
         $this->_html["error"][] = "Can not find  field in themes/LEOTHEME/themeconfig.xml";
         return false;
     }
     foreach ($data->fields as $fields) {
         if (isset($fields->attributes()->objectName) && $fields->attributes()->objectName && $fields->attributes()->objectName == 'theme') {
             $json = json_encode($fields->field);
             $theme = json_decode($json, TRUE);
             $new_theme = new Theme($id_theme);
             foreach ($theme as $k => $field) {
                 $new_theme->{$k} = $field;
             }
             if ($new_theme->update()) {
                 foreach ($data->fields as $items) {
                     if ($items->attributes()->objectName == "theme_meta") {
                         $jsons = json_encode($items);
                         $item = json_decode($jsons, TRUE);
                         $meta = $this->getMetaById($id_theme);
                         if (count($item) > 0) {
                             $this->deleteMeta($id_theme);
                         }
                         foreach ($item['field'] as $row) {
                             $this->addMeta($row, $id_theme);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #4
0
 public function executeUpdate($request)
 {
     $object = $this->getRequestParameter('object');
     $user = User::getByApiKey($request->getParameter('login_id'), $request->getParameter('api_key'));
     if (!$user) {
         $output = '<rsp stat="fail"><err code="2" msg="login_id and api_key do not match" /></rsp>';
     } elseif ($object == 'application') {
         $form = new ApplicationForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url')));
         if ($form->isValid()) {
             $application = Application::update($form->getValues(), $user);
             if ($application) {
                 $output = '<rsp stat="ok">' . $application->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="4" msg="Unable to update application." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'comment') {
         $form = new CommentForm();
         $application_id = $module_id = $theme_id = null;
         if ($request->getParameter('application_id')) {
             $application_id = $request->getParameter('application_id');
         }
         if ($request->getParameter('module_id')) {
             $module_id = $request->getParameter('module_id');
         }
         if ($request->getParameter('theme_id')) {
             $theme_id = $request->getParameter('theme_id');
         }
         $form->bind(array('comment' => $request->getParameter('comment'), 'application_id' => $application_id, 'module_id' => $module_id, 'theme_id' => $theme_id));
         if ($form->isValid()) {
             $comment = Comment::update($form->getValues(), $user);
             $output = '<rsp stat="ok">' . $comment->getXML() . '</rsp>';
         } else {
             $output = '<rsp stat="fail"><err code="3" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'module') {
         $form = new ModuleForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url'), 'application_id' => $request->getParameter('application_id')));
         if ($form->isValid()) {
             $module = Madule::update($form->getValues(), $user);
             if ($module) {
                 $output = '<rsp stat="ok">' . $module->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="4" msg="Unable to update module." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'theme') {
         $form = new ThemeForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description')), $request->getFiles());
         if ($form->isValid()) {
             $theme = Theme::update($form->getValues(), $user);
             if ($theme) {
                 $output = '<rsp stat="ok">' . $theme->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="5" msg="Unable to update theme." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="5" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'theme_group') {
         $output = '<rsp stat="fail"><err code="6" msg="This object is not supported for update" /></rsp>';
     } elseif ($object == 'user') {
         $form = new UserForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'password' => $request->getParameter('password'), 'password2' => $request->getParameter('password'), 'email' => $request->getParameter('email'), 'role' => null));
         if ($form->isValid()) {
             $update_user = User::update($form->getValues(), $user);
             if ($update_user) {
                 $output = '<rsp stat="ok">' . $update_user->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="7" msg="Unable to update user." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="7" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     }
     $this->output = $output;
     $this->setTemplate('index');
 }