/** * Creates a product based on the data entered in the "new" action */ public function createAction() { if (!parent::isValidRequest(new CountryValidation())) { return parent::redirect('country/new'); } try { $code = trim($this->request->get('code')); $existingCountry = Country::findFirst(array('conditions' => 'code = ?0', 'bind' => array($code))); if ($existingCountry) { $this->flash->notice('Country with code <b>' . $code . '</b> address allready exists.'); return parent::redirect('country/new'); } else { $country = new Country(); $country->code = $code; $country->name = trim($this->request->get('name')); $country->save(); $this->flash->success('Country created succesfully.'); } } catch (Exception $ex) { $this->flash->error('An error occured when trying to create the new Country.'); } return $this->redirect('country'); #$this->view->disable(); }
/** * Creates a product based on the data entered in the "new" action */ public function createAction() { $proxyList = $this->request->get('proxyId'); if (!parent::isValidRequest(new BatchValidation()) || empty($proxyList)) { if (empty($proxyList)) { $this->flash->notice('Please select at least 1 proxy.'); } return parent::redirect('batch/new', ['proxyId' => implode(',', $this->request->get('proxyId'))]); } try { $name = trim($this->request->get('name')); $existingBatch = Batch::findFirst(array('conditions' => 'name = ?0', 'bind' => array($name))); if ($existingBatch) { $this->flash->notice('Batch name allready exists.'); return parent::redirect('batch/new', ['proxyId' => implode(',', $this->request->get('proxyId'))]); } else { $urlId = $this->request->get('address'); $proxyIds = $this->request->get('proxyId'); $batch = new Batch(); $batch->urlId = $urlId; $batch->name = $name; $batch->save(); # THE BIG KAHUNA :) if ($this->config->application->debug) { set_time_limit(0); } BatchHelper::create($this->config, $batch->id, $urlId, $proxyIds); $this->flash->success('Batch created succesfully.'); } } catch (\Exception $ex) { $this->flash->error('An error occured when trying to create the new batch.'); } $returnUrl = isset($batch) ? 'batch?batchId=' . $batch->id : 'batch'; return $this->redirect($returnUrl); #$this->view->disable(); }
/** * Updates a product based on the data entered in the "edit" action */ public function saveAction($id) { if (!parent::isValidId($id) || !parent::isValidRequest(new ProxyValidation())) { return parent::redirect('proxy/edit/' . $id); } try { $address = trim($this->request->get('address')); $existingProxy = Proxy::findFirst(array('conditions' => 'address = ?0', 'bind' => array($address))); if (isset($existingProxy->id) && $existingProxy->id != $id) { $this->flash->notice('Proxy exists with same address.'); return parent::redirect('proxy/edit/' . $id); } else { $proxy = Proxy::findFirst($id); $proxy->countryId = $this->request->get('countryId'); $proxy->address = $address; $proxy->save(); $this->flash->success('Proxy updated succesfully.'); } } catch (\Exception $ex) { $this->flash->error('An error occured when trying to update the proxy.'); } return $this->redirect('proxy'); }
/** * Updates a product based on the data entered in the "edit" action */ public function saveAction($id) { if (!parent::isValidId($id) || !parent::isValidRequest(new UrlValidation())) { return parent::redirect('url/edit/' . $id); } try { $address = $this->request->get('address'); $existingUrl = Url::findFirst(array('conditions' => 'address = ?0', 'bind' => array($address))); if (isset($existingUrl->id) && $existingUrl->id != $id) { $this->flash->notice('Url exists with same address.'); return parent::redirect('url/edit/' . $id); } else { $url = Url::findFirst($id); $url->address = $address; $url->save(); $this->flash->success('Url updated succesfully.'); } } catch (\Exception $ex) { $this->flash->error('An error occured when trying to update the url.'); } return $this->redirect('url'); }