/**
  * @param int $dataset_id
  * @return array
  */
 public function getDatasetInfo($dataset_id)
 {
     $dataset_id = (int) $dataset_id;
     if (!$dataset_id) {
         return array();
     }
     $sql = "SELECT dataset_name, dataset_key FROM " . $this->db->table("datasets") . " WHERE dataset_id = " . $dataset_id;
     $result = $this->db->query($sql);
     if (!$result->row['dataset_name']) {
         return array();
     }
     $dataset = new ADataset($result->row['dataset_name'], $result->row['dataset_key']);
     $output['dataset_name'] = $result->row['dataset_name'];
     $output['dataset_key'] = $result->row['dataset_key'];
     $output['num_rows'] = sizeof($dataset->getRows());
     $output['dataset_properties'] = $dataset->getDatasetProperties();
     if (!$output['dataset_properties']) {
         unset($output['dataset_properties']);
     }
     $cols = $dataset->getColumnDefinitions();
     if ($cols) {
         foreach ($cols as $column) {
             $output['dataset_column_definition'][] = array($column['dataset_column_name'] => $column['dataset_column_type']);
         }
     }
     $output['dataset_column_properties'] = $dataset->getColumnsProperties();
     if (!$output['dataset_column_properties']) {
         unset($output['dataset_column_properties']);
     }
     return $output;
 }
 /**
  * @param string $xml_source  - xml as string or full filename to xml-file
  * @param string $mode
  * @return bool
  */
 public function load($xml_source, $mode = 'string')
 {
     if ($mode == 'string') {
         $xml_obj = simplexml_load_string($xml_source);
     } elseif ($mode == 'file') {
         $xml_obj = simplexml_load_file($xml_source);
     }
     if ($xml_obj) {
         $xmlname = $xml_obj->getName();
         if ($xmlname == 'template_layouts') {
             $load = new ALayoutManager();
             $load->loadXML(array('xml' => $xml_source));
         } elseif ($xmlname == 'datasets') {
             $load = new ADataset();
             $load->loadXML(array('xml' => $xml_source));
         } elseif ($xmlname == 'forms') {
             $load = new AFormManager();
             $load->loadXML(array('xml' => $xml_source));
         } else {
             return false;
         }
     } else {
         return false;
     }
     return true;
 }
Esempio n. 3
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->_validate()) {
         $this->loadModel('tool/backup');
         $bkp = $this->model_tool_backup->backup($this->request->post['backup'], $this->request->post['backup_rl'], $this->request->post['backup_config']);
         if ($bkp) {
             $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
             $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => 'Manual Backup', 'version' => VERSION, 'backup_file' => $this->model_tool_backup->backup_filename . '.tar.gz', 'backup_date' => date("Y-m-d H:i:s", time()), 'type' => 'backup', 'user' => $this->user->getUsername()));
         }
         if ($this->model_tool_backup->error) {
             $this->session->data['error'] = $this->model_tool_backup->error;
             $this->redirect($this->html->getSecureURL('tool/backup'));
         } else {
             $this->loadLanguage('tool/backup');
             $this->session->data['success'] = $this->language->get('text_success_backup');
             $this->redirect($this->html->getSecureURL('tool/install_upgrade_history'));
         }
         //update controller data
         $this->extensions->hk_UpdateData($this, __FUNCTION__);
     } else {
         return $this->dispach('error/permission');
     }
 }
 public function getTotalRows($filter = array())
 {
     if ($filter) {
         $filter['column_name'] = 'name';
         $filter['operator'] = 'like';
     }
     $dataset = new ADataset('install_upgrade_history', 'admin');
     $rows = $dataset->getTotalRows($filter);
     return $rows;
 }
Esempio n. 5
0
 public function main()
 {
     $this->loadLanguage('common/header');
     $cache_name = 'admin_menu';
     //$this->data['menu_items'] = $this->cache->get($cache_name);
     if (!$this->data['menu_items']) {
         $menu = new ADataset('menu', 'admin');
         $this->data['menu_items'] = $menu->getRows();
         // need to resort by sort_order property and exlude disabled extension items
         $enabled_extension = $this->extensions->getEnabledExtensions();
         $offset = 0;
         // it needs for process repeating order numbers
         $tmp = array();
         foreach ($this->data['menu_items'] as $i => $item) {
             if ($i > 0) {
                 if ($this->data['menu_items'][$i - 1]['parent_id'] != $item['parent_id']) {
                     $offset = 0;
                 }
             }
             //checks for disabled extension
             if ($item['item_type'] == 'extension') {
                 // looks for this name in enabled extensions list. if is not there - skip it
                 if (!$this->_find_itemId_in_extensions($item['item_id'], $enabled_extension)) {
                     continue;
                 } else {
                     // if all fine - loads language of extension for menu item text show
                     if (strpos($item['item_url'], 'http') === false) {
                         $this->loadLanguage($item['item_id'] . '/' . $item['item_id'], 'silent');
                         $item['language'] = $item['item_id'] . '/' . $item['item_id'];
                     }
                 }
             }
             if (isset($tmp[$item['parent_id']][$item['sort_order']])) {
                 $offset++;
             }
             $tmp[$item['parent_id']][$item['sort_order'] + $offset] = $item;
         }
         $this->data['menu_items'] = array();
         foreach ($tmp as $item) {
             ksort($item);
             $this->data['menu_items'] = array_merge($this->data['menu_items'], $item);
         }
         unset($tmp);
         // now set menu array
         $this->cache->set($cache_name, $this->data['menu_items']);
     }
     $this->data['admin_menu'] = $this->_buildMenuArray($this->data['menu_items']);
     $this->view->assign('menu', $this->data['admin_menu']);
     $this->processTemplate('common/menu.tpl');
     //use to update data before render
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Esempio n. 6
0
 /**
  * @throws AException
  * NOTE: this method have a few hk_processData calls.
  */
 public function main()
 {
     $error_msg = array();
     $cart_rt = 'checkout/cart';
     $product_rt = 'product/product';
     $checkout_rt = 'checkout/shipping';
     $home_rt = 'index/home';
     //is this an embed mode
     if ($this->config->get('embed_mode') == true) {
         $cart_rt = 'r/checkout/cart/embed';
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     //process all possible requests first
     if ($this->request->is_GET() && isset($this->request->get['product_id'])) {
         if (isset($this->request->get['option'])) {
             $option = $this->request->get['option'];
         } else {
             $option = array();
         }
         if (isset($this->request->get['quantity'])) {
             $quantity = $this->request->get['quantity'];
         } else {
             $quantity = 1;
         }
         unset($this->session->data['shipping_methods']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['payment_methods']);
         unset($this->session->data['payment_method']);
         $this->cart->add($this->request->get['product_id'], $quantity, $option);
         $this->extensions->hk_ProcessData($this, 'add_product');
         $this->redirect($this->html->getSecureURL($cart_rt));
     } else {
         if ($this->request->is_GET() && isset($this->request->get['remove'])) {
             //remove product with button claick.
             $this->cart->remove($this->request->get['remove']);
             $this->extensions->hk_ProcessData($this, 'remove_product');
             $this->redirect($this->html->getSecureURL($cart_rt));
         } else {
             if ($this->request->is_POST()) {
                 //if this is coupon, validate and apply
                 if (isset($this->request->post['coupon']) && $this->_validateCoupon()) {
                     $this->session->data['coupon'] = $this->request->post['coupon'];
                     $this->data['success'] = $this->session->data['success'] = $this->language->get('text_coupon_success');
                     unset($this->session->data['success']);
                     //process data
                     $this->extensions->hk_ProcessData($this, 'apply_coupon');
                 }
                 if ($this->error['error_warning']) {
                     $error_msg[] = $this->error['error_warning'];
                 }
                 if (isset($this->request->post['quantity'])) {
                     //we update cart
                     if (!is_array($this->request->post['quantity'])) {
                         $this->loadModel('catalog/product', 'storefront');
                         $product_id = $this->request->post['product_id'];
                         if (isset($this->request->post['option'])) {
                             $options = $this->request->post['option'];
                         } else {
                             $options = array();
                         }
                         //for FILE-attributes
                         if (has_value($this->request->files['option']['name'])) {
                             $fm = new AFile();
                             foreach ($this->request->files['option']['name'] as $id => $name) {
                                 $attribute_data = $this->model_catalog_product->getProductOption($product_id, $id);
                                 $attribute_data['settings'] = unserialize($attribute_data['settings']);
                                 $file_path_info = $fm->getUploadFilePath($attribute_data['settings']['directory'], $name);
                                 $options[$id] = $file_path_info['name'];
                                 if (!has_value($name)) {
                                     continue;
                                 }
                                 if ($attribute_data['required'] && !$this->request->files['option']['size'][$id]) {
                                     $this->session->data['error'] = $this->language->get('error_required_options');
                                     $this->redirect($_SERVER['HTTP_REFERER']);
                                 }
                                 $file_data = array('option_id' => $id, 'name' => $file_path_info['name'], 'path' => $file_path_info['path'], 'type' => $this->request->files['option']['type'][$id], 'tmp_name' => $this->request->files['option']['tmp_name'][$id], 'error' => $this->request->files['option']['error'][$id], 'size' => $this->request->files['option']['size'][$id]);
                                 $file_errors = $fm->validateFileOption($attribute_data['settings'], $file_data);
                                 if (has_value($file_errors)) {
                                     $this->session->data['error'] = implode('<br/>', $file_errors);
                                     $this->redirect($_SERVER['HTTP_REFERER']);
                                 } else {
                                     $result = move_uploaded_file($file_data['tmp_name'], $file_path_info['path']);
                                     if (!$result || $this->request->files['package_file']['error']) {
                                         $this->session->data['error'] .= '<br>Error: ' . getTextUploadError($this->request->files['option']['error'][$id]);
                                         $this->redirect($_SERVER['HTTP_REFERER']);
                                     }
                                 }
                                 $dataset = new ADataset('file_uploads', 'admin');
                                 $dataset->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $file_path_info['name'], 'type' => $file_data['type'], 'section' => 'product_option', 'section_id' => $attribute_data['attribute_id'], 'path' => $file_path_info['path']));
                             }
                         }
                         if ($text_errors = $this->model_catalog_product->validateProductOptions($product_id, $options)) {
                             $this->session->data['error'] = $text_errors;
                             //send options values back via _GET
                             $url = '&' . http_build_query(array('option' => $this->request->post['option']));
                             $this->redirect($this->html->getSecureURL($product_rt, '&product_id=' . $this->request->post['product_id'] . $url));
                         }
                         $this->cart->add($this->request->post['product_id'], $this->request->post['quantity'], $options);
                     } else {
                         foreach ($this->request->post['quantity'] as $key => $value) {
                             $this->cart->update($key, $value);
                         }
                     }
                     unset($this->session->data['shipping_methods']);
                     unset($this->session->data['shipping_method']);
                     unset($this->session->data['payment_methods']);
                     unset($this->session->data['payment_method']);
                 }
                 if (isset($this->request->post['remove'])) {
                     foreach (array_keys($this->request->post['remove']) as $key) {
                         $this->cart->remove($key);
                     }
                 }
                 $this->extensions->hk_ProcessData($this);
                 //next page is requested after cart update
                 if (isset($this->request->post['next_step'])) {
                     $this->redirect($this->html->getSecureURL($this->request->post['next_step']));
                 }
                 if (isset($this->request->post['redirect'])) {
                     $this->session->data['redirect'] = $this->request->post['redirect'];
                 }
                 if (isset($this->request->post['quantity']) || isset($this->request->post['remove'])) {
                     unset($this->session->data['shipping_methods']);
                     unset($this->session->data['shipping_method']);
                     unset($this->session->data['payment_methods']);
                     unset($this->session->data['payment_method']);
                     $this->redirect($this->html->getSecureURL($cart_rt));
                 }
             }
         }
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false));
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('checkout/cart'), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator')));
     if ($this->cart->hasProducts()) {
         if (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
             $error_msg[] = $this->language->get('error_stock');
         }
         $this->loadModel('tool/seo_url', 'storefront');
         $form = new AForm();
         $form->setForm(array('form_name' => 'cart'));
         $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'cart', 'action' => $this->html->getSecureURL($cart_rt)));
         $cart_products = $this->cart->getProducts();
         $product_ids = array();
         foreach ($cart_products as $result) {
             $product_ids[] = (int) $result['product_id'];
         }
         $resource = new AResource('image');
         $thumbnails = $resource->getMainThumbList('products', $product_ids, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
         $products = array();
         foreach ($cart_products as $result) {
             $option_data = array();
             $thumbnail = $thumbnails[$result['product_id']];
             foreach ($result['option'] as $option) {
                 $title = '';
                 if ($option['element_type'] == 'H') {
                     continue;
                 }
                 //hide hidden options
                 $value = $option['value'];
                 // hide binary value for checkbox
                 if ($option['element_type'] == 'C' && in_array($value, array(0, 1))) {
                     $value = '';
                 }
                 // strip long textarea value
                 if ($option['element_type'] == 'T') {
                     $title = strip_tags($value);
                     $title = str_replace('\\r\\n', "\n", $title);
                     $value = str_replace('\\r\\n', "\n", $value);
                     if (mb_strlen($value) > 64) {
                         $value = mb_substr($value, 0, 64) . '...';
                     }
                 }
                 $option_data[] = array('name' => $option['name'], 'value' => $value, 'title' => $title);
             }
             $products[] = array('remove' => $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'remove[' . $result['key'] . ']')), 'remove_url' => $this->html->getSecureURL($cart_rt, '&remove=' . $result['key']), 'key' => $result['key'], 'name' => $result['name'], 'model' => $result['model'], 'thumb' => $thumbnail, 'option' => $option_data, 'quantity' => $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity[' . $result['key'] . ']', 'value' => $result['quantity'], 'attr' => ' size="3" ', 'style' => 'short')), 'stock' => $result['stock'], 'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))), 'total' => $this->currency->format($this->tax->calculate($result['total'], $result['tax_class_id'], $this->config->get('config_tax'))), 'href' => $this->html->getSEOURL($product_rt, '&key=' . $result['key'], true));
         }
         $this->data['products'] = $products;
         $this->data['form']['update'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_update')));
         $this->data['form']['checkout'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'checkout', 'text' => $this->language->get('button_checkout'), 'style' => 'button'));
         if ($this->config->get('config_cart_weight')) {
             $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class'));
         } else {
             $this->data['weight'] = false;
         }
         $display_totals = $this->cart->buildTotalDisplay();
         $this->data['totals'] = $display_totals['total_data'];
         if (isset($this->session->data['redirect'])) {
             $this->data['continue'] = str_replace('&amp;', '&', $this->session->data['redirect']);
             unset($this->session->data['redirect']);
         } else {
             $this->data['continue'] = $this->html->getURL($home_rt);
         }
         $this->data['form']['continue_shopping'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'continue_shopping', 'text' => $this->language->get('button_shopping'), 'style' => 'button', 'href' => $this->data['continue']));
         $this->data['checkout'] = $this->html->getSecureURL($checkout_rt);
         $this->data['checkout_rt'] = $checkout_rt;
         #Check if order total max/min is set and met
         $cf_total_min = $this->config->get('total_order_minimum');
         $cf_total_max = $this->config->get('total_order_maximum');
         if (!$this->cart->hasMinRequirement()) {
             $this->data['form']['checkout'] = '';
             $error_msg[] = sprintf($this->language->get('error_order_minimum'), $this->currency->format($cf_total_min));
         }
         if (!$this->cart->hasMaxRequirement()) {
             $this->data['form']['checkout'] = '';
             $error_msg[] = sprintf($this->language->get('error_order_maximum'), $this->currency->format($cf_total_max));
         }
         //prepare coupon display
         if ($this->config->get('config_coupon_on_cart_page')) {
             $this->view->assign('coupon_status', $this->config->get('coupon_status'));
             $action = $this->html->getSecureURL($cart_rt);
             $coupon_form = $this->dispatch('blocks/coupon_codes', array('action' => $action));
             $this->view->assign('coupon_form', $coupon_form->dispatchGetOutput());
         }
         if ($this->config->get('config_shipping_tax_estimate')) {
             $form = new AForm();
             $form->setForm(array('form_name' => 'estimate'));
             $this->data['form_estimate']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'estimate', 'action' => $this->html->getSecureURL($cart_rt)));
             $this->data['estimates_enabled'] = true;
         }
         //try to get shipping address details if we have them
         $country_id = $this->config->get('config_country_id');
         if ($this->session->data['shipping_address_id']) {
             $this->loadModel('account/address', 'storefront');
             $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
             $postcode = $shipping_address['postcode'];
             $country_id = $shipping_address['country_id'];
             $zone_id = $shipping_address['zone_id'];
         }
         // use default address of customer for estimate form whe shipping address is unknown
         if (!$zone_id && $this->customer->isLogged()) {
             $this->loadModel('account/address', 'storefront');
             $payment_address = $this->model_account_address->getAddress($this->customer->getAddressId());
             $postcode = $payment_address['postcode'];
             $country_id = $payment_address['country_id'];
             $zone_id = $payment_address['zone_id'];
         }
         if ($this->request->post['postcode']) {
             $postcode = $this->request->post['postcode'];
         }
         if ($this->request->post['country'][0]) {
             $country_id = $this->request->post['country'][0];
         }
         if ($this->request->post['country_zones'][0]) {
             $zone_id = $this->request->post['country_zones'][0];
         }
         if ($zone_id) {
             $this->loadModel('localisation/zone', 'storefront');
             $zone_data = $this->model_localisation_zone->getZone($zone_id);
         }
         $this->data['form_estimate']['postcode'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'postcode', 'value' => $postcode, 'style' => 'short'));
         $this->data['form_estimate']['country_zones'] = $form->getFieldHtml(array('type' => 'zones', 'name' => 'country', 'submit_mode' => 'id', 'value' => $country_id, 'zone_name' => $zone_data['name'], 'zone_value' => $zone_id));
         $this->data['form_estimate']['submit'] = $form->getFieldHtml(array('type' => 'submit', 'name' => $this->language->get('button_text_estimate')));
         if ($this->session->data['error']) {
             $error_msg[] = $this->session->data['error'];
             unset($this->session->data['error']);
         }
         $this->view->assign('error_warning', $error_msg);
         $this->view->setTemplate('pages/checkout/cart.tpl');
     } else {
         $this->data['heading_title'] = $this->language->get('heading_title');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->html->buildElement(array('name' => 'continue', 'type' => 'button', 'text' => $this->language->get('button_continue'), 'href' => $this->html->getURL($home_rt), 'style' => 'button'));
         if ($this->config->get('embed_mode') == true) {
             $this->data['back_url'] = $this->html->getURL('r/product/category');
         }
         $this->view->setTemplate('pages/error/not_found.tpl');
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Esempio n. 7
0
 private function _validateCaptcha()
 {
     if ($this->config->get('config_recaptcha_secret_key')) {
         /** @noinspection PhpIncludeInspection */
         require_once DIR_VENDORS . '/google_recaptcha/autoload.php';
         $recaptcha = new \ReCaptcha\ReCaptcha($this->config->get('config_recaptcha_secret_key'));
         $resp = $recaptcha->verify($this->request->post['g-recaptcha-response'], $this->request->server['REMOTE_ADDR']);
         if (!$resp->isSuccess() && $resp->getErrorCodes()) {
             $this->error['captcha'] = $this->language->get('error_captcha');
             return FALSE;
         }
     } else {
         if (!isset($this->session->data['captcha']) || $this->session->data['captcha'] != $this->request->post['captcha']) {
             $this->error['captcha'] = $this->language->get('error_captcha');
             return FALSE;
         }
     }
     if (mb_strlen($this->request->post['username']) < 1) {
         $this->error['username'] = $this->language->get('error_username');
         return FALSE;
     }
     $password_reset = new ADataset('admin_pass_reset', $this->request->post['username'], 'silent');
     $reset_data = $password_reset->getDatasetProperties();
     $email = $reset_data['email'];
     $hash = $reset_data['hash'];
     if (empty($email) || $hash != $this->request->get['hash']) {
         $this->error['warning'] = $this->language->get('error_hash');
     } else {
         $this->loadModel('user/user');
         $users = $this->model_user_user->getUsers(array('search' => "email = '" . $this->db->escape($email) . "'"));
         if (empty($users)) {
             $this->error['warning'] = $this->language->get('error_hash');
         } else {
             $this->user_data = $users[0];
         }
     }
     $this->extensions->hk_ValidateData($this);
     if (!$this->error) {
         //destroy scratch data
         $password_reset->dropDataset();
         return TRUE;
     } else {
         return FALSE;
     }
 }
Esempio n. 8
0
 /**
  * process uploads of files from form file element
  * @param array $files - usually it's a $_FILES array
  * @return array - list of absolute pathes of moved files
  */
 public function processFileUploads($files = array())
 {
     if ($this->fields) {
         $this->_loadFields();
     }
     $output = array();
     foreach ($this->fields as $field) {
         if ($field['element_type'] != 'U') {
             continue;
         }
         $fm = new AFile();
         $file_path_info = $fm->getUploadFilePath($field['settings']['directory'], $files[$field['field_name']]['name']);
         $result = move_uploaded_file($files[$field['field_name']]['tmp_name'], $file_path_info['path']);
         if ($result) {
             $output[$field['field_name']] = array('display_name' => $field['name'], 'path' => $file_path_info['path']);
         } else {
             $err = new AError("AForm error: can't to move uploaded file " . $files[$field['field_name']]['tmp_name'] . " to " . $file_path_info['path']);
             $err->toLog()->toDebug();
         }
         $dataset = new ADataset('file_uploads', 'admin');
         $dataset->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $file_path_info['name'], 'type' => $files[$field['field_name']]['type'], 'section' => 'AForm:' . $this->form['form_name'] . ":" . $field['field_name'], 'section_id' => '', 'path' => $file_path_info['path']));
     }
     return $output;
 }
 /**
  * @return bool
  */
 private function _upgradeCore()
 {
     $package_info =& $this->session->data['package_info'];
     if (versionCompare(VERSION, $package_info['package_version'], ">=")) {
         $this->session->data['error'] = str_replace('%VERSION%', VERSION, $this->language->get('error_core_version')) . $package_info['package_version'] . '!';
         unset($this->session->data['package_info']);
         $this->redirect($this->_get_begin_href());
     }
     $corefiles = $package_info['package_content']['core'];
     $pmanager = new APackageManager();
     //#1 backup files
     $backup = new ABackup('abantecart_' . str_replace('.', '', VERSION));
     foreach ($corefiles as $core_file) {
         if (file_exists(DIR_ROOT . '/' . $core_file)) {
             if (!$backup->backupFile(DIR_ROOT . '/' . $core_file, false)) {
                 return false;
             }
         }
     }
     //#2 backup database
     if ($backup->dumpDatabase()) {
         $backup_dirname = $backup->getBackupName();
         if ($backup_dirname) {
             if (!$backup->dumpDatabase()) {
                 $this->session->data['error'] = $backup->error;
                 return false;
             }
             if (!$backup->archive(DIR_BACKUP . $backup_dirname . '.tar.gz', DIR_BACKUP, $backup_dirname)) {
                 $this->session->data['error'] = $backup->error;
                 return false;
             }
         } else {
             $this->session->data['error'] = 'Error: Unknown directory name for backup.';
             return false;
         }
         $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
         $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => 'Backup before core upgrade. Core version: ' . VERSION, 'version' => VERSION, 'backup_file' => $backup_dirname . '.tar.gz', 'backup_date' => date("Y-m-d H:i:s", time()), 'type' => 'backup', 'user' => $this->user->getUsername()));
     } else {
         $this->session->data['error'] = $backup->error;
         return false;
     }
     //#3 replace files
     $pmanager->replaceCoreFiles();
     //#4 run sql and php upgare procedure files
     $package_dirname = $package_info['tmp_dir'] . $package_info['package_dir'];
     /**
      * @var SimpleXmlElement $config
      */
     $config = simplexml_load_string(file_get_contents($package_dirname . '/package.xml'));
     if (!$config) {
         $this->session->data['error'] = 'Error: package.xml from package content is not valid xml-file!';
         unset($this->session->data['package_info']);
         $this->redirect($this->_get_begin_href());
     }
     $pmanager->upgradeCore($config);
     $pmanager->updateCoreVersion((string) $config->version);
     return true;
 }
Esempio n. 10
0
 /**
  * @param SimpleXmlElement $config
  */
 public function upgradeCore($config)
 {
     //clear all cache
     $this->cache->delete('*');
     $package_dirname = $this->session->data['package_info']['package_dir'];
     $package_tmpdir = $this->session->data['package_info']['tmp_dir'];
     // running sql upgrade script if it exists
     if (isset($config->upgrade->sql)) {
         $file = $package_tmpdir . $package_dirname . '/' . (string) $config->upgrade->sql;
         if (is_file($file)) {
             $this->db->performSql($file);
         }
     }
     // running php upgrade script if it exists
     if (isset($config->upgrade->trigger)) {
         $file = $package_tmpdir . $package_dirname . '/' . (string) $config->upgrade->trigger;
         if (is_file($file)) {
             /** @noinspection PhpIncludeInspection */
             include $file;
         }
     }
     // write to history
     $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
     $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => 'Core upgrade', 'version' => $this->session->data['package_info']['package_version'], 'backup_file' => '', 'backup_date' => '', 'type' => 'upgrade', 'user' => $this->user->getUsername()));
 }
 /**
  * @param string $extension_txt_id
  * @return bool
  */
 public function delete($extension_txt_id)
 {
     if (!trim($extension_txt_id)) {
         $this->log->write('Error! Abantecart tried to delete by empty extension_txt_id');
         return false;
     }
     $info = $this->extensions->getExtensionInfo($extension_txt_id);
     $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
     $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $extension_txt_id, 'version' => $info['version'], 'backup_file' => '', 'backup_date' => '', 'type' => 'delete', 'user' => $this->user->getUsername()));
     $this->db->query("DELETE FROM " . $this->db->table("extensions") . " WHERE `type` = '" . $info['type'] . "' AND `key` = '" . $this->db->escape($extension_txt_id) . "'");
     $this->deleteDependant($extension_txt_id);
     $this->session->data['package_info']['ftp'] = false;
     $pmanager = new APackageManager();
     $result = $pmanager->removeDir(DIR_EXT . $extension_txt_id);
     if (!$result) {
         $message = "Error: Can't to delete file or directory: '" . DIR_EXT . $extension_txt_id . "'. No file permissions, change permissions to 777 with your FTP access";
         $this->session->data['error'] = $message;
     }
     // refresh data about updates
     $this->load->model('tool/updater');
     $this->model_tool_updater->check4updates();
     return true;
 }