public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // check rights for this blog at first and unsubscribe user if he hasn't
     $sql = "SELECT c.id FROM blog_emailsubscription s\n        JOIN wa_contact c ON s.contact_id = c.id\n        WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $unsubscribe_contact_ids = array();
     foreach ($model->query($sql) as $row) {
         $rights = 1;
         try {
             $rights = blogHelper::checkRights($blog_id, $row['id'], blogRightConfig::RIGHT_READ);
         } catch (Exception $e) {
             $rights = 0;
         }
         if (!$rights) {
             $unsubscribe_contact_ids[] = $row['id'];
         }
     }
     if ($unsubscribe_contact_ids) {
         $em = new blogEmailsubscriptionModel();
         $em->deleteByField(array('contact_id' => $unsubscribe_contact_ids, 'blog_id' => $blog_id));
     }
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
 public function execute(&$params)
 {
     $master_id = $params['id'];
     $merge_ids = $params['contacts'];
     $all_ids = array_merge($merge_ids, array($master_id));
     $m = new waModel();
     //
     // All the simple cases: update contact_id in tables
     //
     foreach (array(array('shop_cart_items', 'contact_id'), array('shop_checkout_flow', 'contact_id'), array('shop_order', 'contact_id'), array('shop_order_log', 'contact_id'), array('shop_product', 'contact_id'), array('shop_product_reviews', 'contact_id'), array('shop_affiliate_transaction', 'contact_id')) as $pair) {
         list($table, $field) = $pair;
         $sql = "UPDATE {$table} SET {$field} = :master WHERE {$field} in (:ids)";
         $m->exec($sql, array('master' => $master_id, 'ids' => $merge_ids));
     }
     //
     // shop_affiliate_transaction
     //
     $balance = 0.0;
     $sql = "SELECT * FROM shop_affiliate_transaction WHERE contact_id=? ORDER BY id";
     foreach ($m->query($sql, $master_id) as $row) {
         $balance += $row['amount'];
         if ($row['balance'] != $balance) {
             $m->exec("UPDATE shop_affiliate_transaction SET balance=? WHERE id=?", $balance, $row['id']);
         }
     }
     $affiliate_bonus = $balance;
     //
     // shop_customer
     //
     // Make sure it exists
     $cm = new shopCustomerModel();
     $cm->createFromContact($master_id);
     $sql = "SELECT SUM(number_of_orders) FROM shop_customer WHERE contact_id IN (:ids)";
     $number_of_orders = $m->query($sql, array('ids' => $all_ids))->fetchField();
     $sql = "SELECT MAX(last_order_id) FROM shop_customer WHERE contact_id IN (:ids)";
     $last_order_id = $m->query($sql, array('ids' => $all_ids))->fetchField();
     $sql = "UPDATE shop_customer SET number_of_orders=?, last_order_id=?, affiliate_bonus=? WHERE contact_id=?";
     $m->exec($sql, ifempty($number_of_orders, 0), ifempty($last_order_id, null), ifempty($affiliate_bonus, 0), $master_id);
     if ($number_of_orders) {
         shopCustomers::recalculateTotalSpent($master_id);
     }
     wa('shop')->event('customers_merge', $params);
     return null;
 }
 public function execute(&$params)
 {
     $master_id = $params['id'];
     $merge_ids = $params['contacts'];
     $m = new waModel();
     foreach (array(array('blog_comment', 'contact_id')) as $pair) {
         list($table, $field) = $pair;
         $sql = "UPDATE {$table} SET {$field} = :master WHERE {$field} in (:ids)";
         $m->exec($sql, array('master' => $master_id, 'ids' => $merge_ids));
     }
     return null;
 }
 public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
Example #5
0
<?php

$sqls = array();
$sqls[] = 'ALTER TABLE  `blog_comment` CHANGE  `email`  `email` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL';
$sqls[] = 'ALTER TABLE  `blog_comment` CHANGE  `name`  `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL';
$sqls[] = 'ALTER TABLE  `blog_comment` CHANGE  `site`  `site` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL';
$sqls[] = 'ALTER TABLE  `blog_post` CHANGE  `text`  `text` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL';
$model = new waModel();
foreach ($sqls as $sql) {
    try {
        $model->exec($sql);
    } catch (Exception $ex) {
        if (class_exists('waLog')) {
            waLog::log(basename(__FILE__) . ': ' . $ex->getMessage(), 'blog-update.log');
        }
    }
}
Example #6
0
<?php

$model = new waModel();
try {
    $model->query("SELECT type FROM shop_affiliate_transaction WHERE 0");
} catch (waDbException $e) {
    $model->exec("ALTER TABLE shop_affiliate_transaction ADD type VARCHAR (32) NULL DEFAULT NULL");
    // order_bonus
    $model->exec("UPDATE shop_affiliate_transaction SET type='order_bonus'\n                  WHERE type IS NULL AND order_id IS NOT NULL AND amount > 0");
    // deposit
    $model->exec("UPDATE shop_affiliate_transaction SET type='deposit'\n                  WHERE type IS NULL AND order_id IS NULL AND amount > 0");
    // order_cancel
    $model->exec("UPDATE shop_affiliate_transaction SET type='order_cancel'\n                  WHERE type IS NULL AND order_id IS NOT NULL AND (comment IS NULL OR comment = '') AND amount < 0");
    // order_discount
    $model->exec("UPDATE shop_affiliate_transaction SET type='order_discount'\n                  WHERE type IS NULL AND order_id IS NOT NULL AND amount < 0");
    // withdrawal
    $model->exec("UPDATE shop_affiliate_transaction SET type='withdrawal'\n                  WHERE type IS NULL AND order_id IS NULL AND amount < 0");
}
Example #7
0
<?php

$model = new waModel();
$plugin_model = new shopPluginModel();
$plugings = $plugin_model->getByField('plugin', 'invoicejur', true);
if ($plugings) {
    foreach ($plugings as $p) {
        $settings = $model->query("SELECT name, value FROM shop_plugin_settings WHERE id = i:0", $p['id'])->fetchAll('name', true);
        $company = !empty($settings['cust_company']) ? $settings['cust_company'] : 'company';
        $inn = !empty($settings['cust_inn']) ? $settings['cust_inn'] : 'inn';
        $model->exec("UPDATE shop_order_params SET name = 'payment_params_" . $company . "' WHERE name = 'billing_" . $company . "'");
        $model->exec("UPDATE shop_order_params SET name = 'payment_params_" . $inn . "' WHERE name = 'billing_" . $inn . "'");
    }
}
Example #8
0
<?php

$model = new waModel();
try {
    $model->query("SELECT moderation FROM `photos_photo` WHERE 0");
} catch (waException $e) {
    // 0 - waited
    // 1 - approved
    // -1 - declined
    $sql = "ALTER TABLE `photos_photo` ADD COLUMN moderation TINYINT(1) NOT NULL DEFAULT 1";
    $model->query($sql);
}
try {
    $model->query("SELECT `votes_count` FROM `photos_photo` WHERE 0");
} catch (waException $e) {
    $model->exec("ALTER TABLE `photos_photo` ADD COLUMN votes_count INT(11) NOT NULL DEFAULT 0");
}
$contact_id = wa()->getUser()->getId();
$photo_model = new photosPhotoModel();
$data = array();
foreach ($photo_model->select('id, rate')->where('rate > 0')->fetchAll() as $item) {
    $data[] = array('photo_id' => $item['id'], 'contact_id' => $contact_id, 'rate' => $item['rate'], 'datetime' => date('Y-m-d H:i:s'), 'ip' => waRequest::getIp(true));
}
$vote_model = new photosPublicgalleryVoteModel();
$vote_model->multipleInsert($data);
$model->exec("UPDATE `photos_photo` SET votes_count = 1 WHERE rate > 0");
Example #9
0
<?php

$mod = new waModel();
$mod->exec("UPDATE wa_contact_data SET field='address:region' WHERE field='address:state'");
Example #10
0
<?php

$model = new waModel();
try {
    $model->exec("ALTER TABLE shop_order_log ADD INDEX `order_id` (`order_id`)");
} catch (waDbException $e) {
}
try {
    $model->exec("ALTER TABLE shop_order_items DROP INDEX product");
} catch (waDbException $e) {
}
try {
    $model->exec("ALTER TABLE shop_order_items ADD INDEX product_order (product_id, order_id)");
} catch (waDbException $e) {
}
try {
    $model->exec("ALTER TABLE shop_order_items ADD INDEX `order_type` (`order_id`, `type`)");
} catch (waDbException $e) {
}
try {
    $model->exec("ALTER TABLE shop_product_features DROP INDEX sku");
} catch (waDbException $e) {
}
try {
    $model->exec("ALTER TABLE shop_product_features ADD INDEX product_feature (product_id, feature_id, feature_value_id)");
} catch (waDbException $e) {
}
Example #11
0
<?php

$model = new waModel();
$model->exec("CREATE TABLE IF NOT EXISTS `wa_contact_field_values` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `parent_field` varchar(64) NOT NULL,\n  `parent_value` varchar(255) NOT NULL,\n  `field` varchar(64) NOT NULL,\n  `value` varchar(255) NOT NULL,\n  `sort` int(11) NOT NULL DEFAULT '0',\n  PRIMARY KEY (`id`),\n  KEY `parent_field` (`parent_field`,`parent_value`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8");
<?php

$model = new waModel();
try {
    $model->exec("ALTER TABLE `checklists_list` CHANGE `color_class` `color_class` VARCHAR(32) NOT NULL DEFAULT 'c-white'");
} catch (waDbException $e) {
}
Example #13
0
<?php

$model = new waModel();
$model->exec("CREATE TABLE IF NOT EXISTS `shop_product_features_selectable` (\n  `product_id` int(11) NOT NULL,\n  `feature_id` int(11) NOT NULL,\n  `value_id` int(11) NOT NULL,\n  PRIMARY KEY (`product_id`,`feature_id`,`value_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
Example #14
0
<?php

$model = new waModel();
$model->exec("ALTER TABLE shop_order_log CHANGE text text TEXT NULL");
Example #15
0
<?php

$model = new waModel();
try {
    $model->query("SELECT route FROM shop_category WHERE 0");
} catch (waDbException $e) {
    $model->exec("ALTER TABLE shop_category ADD route VARCHAR(255) NULL DEFAULT NULL");
}
<?php

$model = new waModel();
$model->exec("UPDATE wa_country SET iso2letter=LOWER(iso2letter), iso3letter=LOWER(iso3letter)");
<?php

$mod = new waModel();
try {
    $mod->exec("SELECT fav_sort FROM wa_region LIMIT 0");
} catch (waDbException $e) {
    $mod->exec("ALTER TABLE `wa_region` ADD `fav_sort` INT NULL DEFAULT NULL");
}
try {
    $mod->exec("SELECT fav_sort FROM wa_country LIMIT 0");
} catch (waDbException $e) {
    $mod->exec("ALTER TABLE `wa_country` ADD `fav_sort` INT NULL DEFAULT NULL");
}
<?php

$model = new waModel();
try {
    $model->query("SELECT moderation FROM `photos_photo` WHERE 0");
    $model->exec("ALTER TABLE `photos_photo` DROP COLUMN moderation");
} catch (waException $e) {
}
try {
    $model->query("SELECT votes_count FROM `photos_photo` WHERE 0");
    $model->exec("ALTER TABLE `photos_photo` DROP COLUMN votes_count");
} catch (waException $e) {
}
Example #19
0
<?php

$model = new waModel();
$model->exec("DELETE pf FROM shop_product_features pf LEFT JOIN shop_product_skus s ON pf.sku_id = s.id\nWHERE pf.sku_id IS NOT NULL AND s.id IS NULL ");
$model->exec("DELETE FROM shop_feature WHERE (type = '1' OR type = '') AND (name = '' OR name IS NULL)");
$model->exec("UPDATE shop_feature SET type = 'varchar' WHERE type = '1' OR type = ''");
Example #20
0
<?php

// strict mode mysql
$sql = array();
$sql[] = "ALTER TABLE `stickies_sheet` \nCHANGE `background_id` `background_id` varchar(10) DEFAULT ''";
$sql[] = "ALTER TABLE `stickies_sticky` \nCHANGE `size_width` `size_width` int(11) NOT NULL DEFAULT 0,\nCHANGE `size_height` `size_height` int(11) NOT NULL DEFAULT 0,\nCHANGE `position_top` `position_top` int(11) NOT NULL DEFAULT 0,\nCHANGE `position_left` `position_left` int(11) NOT NULL DEFAULT 0,\nCHANGE `color` `color` varchar(16) NOT NULL DEFAULT '',\nCHANGE `font_size` `font_size` int NOT NULL DEFAULT 0";
$model = new waModel();
foreach ($sql as $q) {
    $model->exec($q);
}
Example #21
0
<?php

$model = new waModel();
try {
    $model->exec("SELECT keywords FROM `shop_product_pages` WHERE 0");
} catch (waDbException $e) {
    $model->exec("ALTER TABLE `shop_product_pages` ADD keywords TEXT NULL");
}
try {
    $model->exec("SELECT description FROM `shop_product_pages` WHERE 0");
} catch (waDbException $e) {
    $model->exec("ALTER TABLE `shop_product_pages` ADD description TEXT NULL");
}
try {
    $model->exec("SELECT * FROM `shop_product_page_params` WHERE 0");
    $data = array();
    foreach ($model->query("SELECT * FROM `shop_product_page_params` WHERE name IN ('keywords', 'description')") as $item) {
        $data[$item['page_id']][$item['name']] = $item['value'];
    }
    $page_model = new shopProductPagesModel();
    foreach ($data as $page_id => $item) {
        $page_model->updateById($page_id, $item);
    }
    $model->exec("DROP TABLE `shop_product_page_params`");
} catch (waDbException $e) {
}
Example #22
0
foreach ($files as $file) {
    if (file_exists($path . $file)) {
        unlink($path . $file);
    }
}
// try remove cache (for correct autoload)
try {
    $path_cache = waConfig::get('wa_path_cache') . '/apps/blog/';
    waFiles::delete($path_cache, true);
} catch (Exception $e) {
}
// add new fields to table pages
$model = new waModel();
try {
    $sql = "ALTER TABLE blog_page\n        ADD full_url VARCHAR(255) NULL DEFAULT NULL AFTER url,\n        ADD domain VARCHAR(255) NULL DEFAULT NULL,\n        ADD route VARCHAR(255) NULL DEFAULT NULL,\n        ADD parent_id INT(11) NULL DEFAULT NULL";
    $model->exec($sql);
} catch (waDbException $e) {
    // nothing if fields already exists
}
$model->exec("UPDATE blog_page SET full_url = url WHERE parent_id IS NULL");
// set domain and route for pages
$routing_path = $this->getPath('config', 'routing');
if (file_exists($routing_path)) {
    $routing = (include $routing_path);
    $pages = false;
    foreach ($routing as $domain => $domain_routes) {
        foreach ($domain_routes as $route_id => $route) {
            if (isset($route['app']) && $route['app'] == 'blog') {
                $data = array('domain' => $domain, 'route' => $route['url']);
                $sql = "UPDATE blog_page SET domain = s:domain, route = s:route WHERE domain IS NULL";
                // if not exclude pages then settle all pages to first route of the blog
Example #23
0
<?php

$model = new waModel();
// remove paid_date for refunded orders
$model->exec("UPDATE shop_order\nSET paid_year = NULL, paid_month = NULL, paid_quarter = NULL, paid_date = NULL\nWHERE state_id = 'refunded'");
Example #24
0
<?php

/**
 * Rename snippets to blocks
 */
// remove old files
$path = $this->getAppPath('lib/actions/snippets/');
if (file_exists($path)) {
    waFiles::delete($path);
}
$path = $this->getAppPath('templates/actions/snippets/');
if (file_exists($path)) {
    waFiles::delete($path);
}
// rename table
$model = new waModel();
$exists = false;
try {
    $model->exec("SELECT 1 FROM site_snippet WHERE 0");
    $exists = true;
} catch (waDbException $e) {
}
if ($exists) {
    $model->exec("RENAME TABLE `site_snippet` TO  `site_block`");
}
// change rights key
$sql = "UPDATE wa_contact_rights SET name = 'blocks' WHERE app_id = 'site' AND name = 'snippets'";
$model->exec($sql);
 public function uninstall()
 {
     // check uninstall.php
     $file = $this->getAppConfigPath('uninstall');
     if (file_exists($file)) {
         include $file;
     }
     $file_db = $this->getAppPath('lib/config/db.php');
     if (file_exists($file_db)) {
         $schema = (include $file_db);
         $model = new waModel();
         foreach ($schema as $table => $fields) {
             $sql = "DROP TABLE IF EXISTS " . $table;
             $model->exec($sql);
         }
     }
     // Remove all app settings
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->del($this->application);
     $contact_settings_model = new waContactSettingsModel();
     $contact_settings_model->deleteByField('app_id', $this->application);
     // Remove all rights to app
     $contact_rights_model = new waContactRightsModel();
     $contact_rights_model->deleteByField('app_id', $this->application);
     // Remove logs
     $log_model = new waLogModel();
     $log_model->deleteByField('app_id', $this->application);
     // Remove cache
     waFiles::delete($this->getPath('cache') . '/apps/' . $this->application);
 }
Example #26
0
<?php

$model = new waModel();
$model->exec("UPDATE `shop_set` SET count = 0 WHERE count < 0");
Example #27
0
<?php

$model = new waModel();
try {
    $model->query("SELECT sort FROM shop_service WHERE 0");
} catch (waDbException $e) {
    $sql = 'ALTER TABLE `shop_service` ADD `sort` INT(11) NOT NULL DEFAULT 0';
    $model->exec($sql);
}
$i = 0;
foreach ($model->query("SELECT * FROM shop_service ORDER BY sort, id") as $item) {
    $model->exec("UPDATE shop_service SET sort = {$i} WHERE id = " . $item['id']);
    $i++;
}
try {
    $model->query("SELECT sort FROM shop_service_variants WHERE 0");
} catch (Exception $e) {
    $model->exec("ALTER TABLE shop_service_variants ADD COLUMN `sort` INT(11) NOT NULL DEFAULT 0");
    $model->exec("UPDATE shop_service_variants SET sort = id");
}
Example #28
0
// Create cli.php if not included in distr already
$path = wa()->getConfig()->getRootPath() . '/cli.php';
if (!file_exists($path)) {
    if ($fp = fopen($path, 'w')) {
        $content = <<<CLI
#!/usr/bin/php
<?php
require_once(dirname(__FILE__).'/wa-system/cli.php');

CLI;
        fwrite($fp, $content);
        fclose($fp);
    }
}
// Protect private dirs with .htaccess
$paths = array('log', 'cache', 'config', 'installer');
foreach ($paths as $path) {
    $path = waSystem::getInstance()->getConfig()->getPath($path);
    waFiles::protect($path);
}
// Insert data into tables
foreach (array('wa_country', 'wa_region') as $table) {
    if ($sql = @file_get_contents(dirname(__FILE__) . '/' . $table . '.sql')) {
        try {
            $m = new waModel();
            $m->exec($sql);
        } catch (Exception $e) {
            waLog::log('Unable to populate ' . $table . ': ' . $e->getMessage() . "\n" . $e->getTraceAsString());
        }
    }
}
Example #29
0
<?php

$mod = new waModel();
if ($sql = @file_get_contents($this->getAppPath('lib/config/wa_region.sql'))) {
    $mod->exec($sql);
}
Example #30
0
<?php

$model = new waModel();
try {
    $model->query("SELECT sku_count FROM shop_product WHERE 0");
} catch (waDbException $e) {
    $model->exec("ALTER TABLE shop_product ADD sku_count INT (11) NOT NULL DEFAULT 1");
}
$model->exec("UPDATE shop_product p JOIN (\n    SELECT product_id, COUNT( * ) sku_count\n    FROM shop_product_skus\n    GROUP BY product_id HAVING count(*) > 1\n) t ON p.id = t.product_id SET p.sku_count = t.sku_count");