/** * Action delete */ public function action_delete() { // Auto render off $this->auto_render = FALSE; // Get id from param, if there is nothing then throw to 404 $id = $this->request->param('key'); if (!$id) { throw HTTP_Exception::factory(404); } // Get wrapper, if there is nothing then throw to 404 $wrapper = Tbl::factory('wrappers')->get($id); if (!$wrapper) { throw HTTP_Exception::factory(404); } // Database transaction start Database::instance()->begin(); // Try try { /** * Check other tables */ // used by divisions $used_divisions = (bool) Tbl::factory('divisions')->where('wrapper_id', '=', $wrapper->id)->read()->count(); // If this warpper is used by division if ($used_divisions) { throw new Warning_Exception(Kohana::message('general', 'wrapper_is_used')); } /** * Delete */ // Delete file $file = "wrapper/{$wrapper->segment}"; Cms_Helper::delete_file($file, $this->settings->front_tpl_dir); // Delete $wrapper->delete(); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success')); // Redirect to wrapper index $this->redirect(URL::site("{$this->settings->backend_name}/wrappers/index", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation')); } catch (Warning_Exception $e) { // Database rollback Database::instance()->rollback(); // Add Notice::add(Notice::WARNING, $e->getMessage()); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR); } // Redirect to wrapper edit $this->redirect(URL::site("{$this->settings->backend_name}/wrappers/edit/{$wrapper->id}", 'http')); }
/** * Action delete */ public function action_delete() { // Auto render off $this->auto_render = FALSE; // Get id from param, if there is nothing then throw to 404 $id = $this->request->param('key'); if (!$id) { throw HTTP_Exception::factory(404); } // Get division, if there is nothing then throw to 404 $division = Tbl::factory('divisions')->get($id); if (!$division) { throw HTTP_Exception::factory(404); } // Database transaction start Database::instance()->begin(); // Try try { /** * Check other tables */ // used by items $used_items = (bool) Tbl::factory('items')->where('division_id', '=', $division->id)->read()->count(); // used by categories $used_categories = (bool) Tbl::factory('categories')->where('division_id', '=', $division->id)->read()->count(); // used by fields $used_fields = (bool) Tbl::factory('fields')->where('division_id', '=', $division->id)->read()->count(); // Build tables array $tables = array(); if ($used_items) { $tables[] = 'items'; } if ($used_categories) { $tables[] = 'categories'; } if ($used_fields) { $tables[] = 'fields'; } // If this division is used when throw to warning if ($used_items or $used_categories or $used_fields) { throw new Warning_Exception(Kohana::message('general', 'division_is_used'), array(':tables' => implode(', ', $tables))); } /** * Delete */ // Delete file まずファイルを消す! $file_delete_success = Cms_Helper::delete_file($division->segment, $this->settings->front_tpl_dir . '/division'); if ($file_delete_success) { Cms_Helper::delete_dir($division->segment, $this->settings->item_dir); Cms_Helper::delete_dir($division->segment, $this->settings->image_dir . '/item'); } // Delete $division->delete(); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success')); $this->redirect(URL::site("{$this->settings->backend_name}/divisions/index", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation')); } catch (Warning_Exception $e) { // Database rollback Database::instance()->rollback(); // Add Notice::add(Notice::WARNING, $e->getMessage()); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR, $e->getMessage()); } // Redirect to wrapper edit $this->redirect(URL::site("{$this->settings->backend_name}/divisions/edit/{$division->id}", 'http')); }
/** * Action delete */ public function action_delete() { // Auto render off $this->auto_render = FALSE; // Get id from param, if there is nothing then throw to 404 $segment = $this->request->param('key'); if (!$segment) { throw HTTP_Exception::factory(404); } // Make part and get content from file and direct set to part $part = new stdClass(); $part->segment = $segment; $part->content = Tpl::get_file($segment, $this->settings->front_tpl_dir . '/part'); // If there is nothing then throw to 404 if ($part->content === FALSE) { throw HTTP_Exception::factory(404); } // Try try { /** * Delete */ // Delete file Cms_Helper::delete_file($part->segment, "{$this->settings->front_tpl_dir}/part"); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success')); $this->redirect(URL::site("{$this->settings->backend_name}/parts/index", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Add error notice Notice::add(Notice::ERROR); } // Redirect to wrapper edit $this->redirect(URL::site("{$this->settings->backend_name}/parts/edit/{$part->segment}", 'http')); }
/** * Action delete */ public function action_delete() { // Auto render off $this->auto_render = FALSE; // Get id from param, if there is nothing then throw to 404 $id = $this->request->param('key'); if (!$id) { throw HTTP_Exception::factory(404); } // Get email, if there is nothing then throw to 404 $email = Tbl::factory('emails')->get($id); if (!$email) { throw HTTP_Exception::factory(404); } // Database transaction start Database::instance()->begin(); // Try try { /** * Delete */ // used by email $used_rule_ids = Tbl::factory('email_rules')->where('email_id', '=', $email->id)->read()->as_array(NULL, 'id'); if ($used_rule_ids) { foreach ($used_rule_ids as $used_rule_id) { Tbl::factory('email_rules')->get($used_rule_id)->delete(); } } // Delete file Cms_Helper::delete_file($email->segment, "{$this->settings->front_tpl_dir}/email"); Cms_Helper::delete_file($email->segment, "{$this->settings->front_tpl_dir}/email/confirm"); Cms_Helper::delete_file($email->segment, "{$this->settings->front_tpl_dir}/email/receive"); // Delete $email->delete(); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success')); $this->redirect(URL::site("{$this->settings->backend_name}/emails/index", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR); } // Redirect to wrapper edit $this->redirect(URL::site("{$this->settings->backend_name}/emails/edit/{$email->id}", 'http')); }
/** * Action delete */ public function action_delete() { // Auto render off $this->auto_render = FALSE; // Get division $division = Tbl::factory('divisions')->where('id', '=', $this->item->division_id)->read(1); // Database transaction start Database::instance()->begin(); // Try try { /** * Delete */ // Delete items categories カテゴリーの削除 $used_category_ids = Tbl::factory('items_categories')->where('item_id', '=', $this->item->id)->read()->as_array(NULL, 'id'); if ($used_category_ids) { foreach ($used_category_ids as $used_category_id) { Tbl::factory('items_categories')->get($used_category_id)->delete(); } } // Delete items fields フィールドの削除 $used_field_ids = Tbl::factory('items_fields')->where('item_id', '=', $this->item->id)->read()->as_array(NULL, 'id'); if ($used_field_ids) { foreach ($used_field_ids as $used_field_id) { Tbl::factory('items_fields')->get($used_field_id)->delete(); } } // Delete items tags タグの削除 $used_tag_ids = Tbl::factory('items_tags')->where('item_id', '=', $this->item->id)->read()->as_array(NULL, 'id'); if ($used_tag_ids) { foreach ($used_tag_ids as $used_tag_id) { Tbl::factory('items_tags')->get($used_tag_id)->delete(); } } // Delete item comments コメントの削除 $used_comment_ids = Tbl::factory('received_comments')->where('item_id', '=', $this->item->id)->read()->as_array(NULL, 'id'); if ($used_comment_ids) { foreach ($used_comment_ids as $used_comment_id) { Tbl::factory('received_comments')->get($used_comment_id)->delete(); } } // Delete images イメージの削除 $used_image_ids = Tbl::factory('images')->where('item_id', '=', $this->item->id)->read()->as_array(NULL, 'id'); if ($used_image_ids) { foreach ($used_image_ids as $used_image_id) { Tbl::factory('images')->get($used_image_id)->delete(); } } // Delete image files and directory イメージファイルとディレクトリの削除 Cms_Helper::delete_dir($this->item->segment, $this->settings->image_dir . '/item/' . $division->segment, TRUE); // Delete file Cms_Helper::delete_file($this->item->segment, $this->settings->item_dir . '/' . $division->segment); // Delete $this->item->delete(); // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR); } /** * Redirect to wrapper edit */ $this->redirect(URL::site("{$this->settings->backend_name}/items/{$division->segment}", 'http')); }
/** * Action delete */ public function action_delete() { // Auto render off $this->auto_render = FALSE; // Get id from param, if there is nothing then throw to 404 $segment = $this->request->param('key'); if (!$segment) { throw HTTP_Exception::factory(404); } // Make shape and get content from file and direct set to shape $shape = new stdClass(); $shape->segment = $segment; $shape->content = Tpl::get_file($segment, $this->settings->front_tpl_dir . '/shape'); // If there is nothing then throw to 404 if ($shape->content === FALSE) { throw HTTP_Exception::factory(404); } // Try try { /** * Check other tables */ // used by items $used_items = (bool) Tbl::factory('items')->where('shape_segment', '=', $shape->segment)->read()->count(); // If this shape is used throw to warning if ($used_items) { throw new Warning_Exception(Kohana::message('general', 'shape_is_used')); } /** * Delete */ // Delete file Cms_Helper::delete_file($shape->segment, "{$this->settings->front_tpl_dir}/shape"); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success')); $this->redirect(URL::site("{$this->settings->backend_name}/shapes/index", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation')); } catch (Warning_Exception $e) { // Add Notice::add(Notice::WARNING, $e->getMessage()); } catch (Exception $e) { // Add error notice Notice::add(Notice::ERROR, $e->getMessage() . ' : ' . $e->getFile() . ' : ' . $e->getLine()); } // Redirect to wrapper edit $this->redirect(URL::site("{$this->settings->backend_name}/shapes/edit/{$shape->segment}", 'http')); }