· 4 years ago · May 19, 2021, 10:48 PM
1<?php defined('SYSPATH') or die('No direct script access.');
2/**
3 * Update controllers
4 *
5 * @package OC
6 * @category Update
7 * @author Chema <chema@open-classifieds.com>, Slobodan <slobodan@open-classifieds.com>
8 * @copyright (c) 2009-2014 Open Classifieds Team
9 * @license GPL v3
10 */
11class Controller_Panel_Update extends Auth_Controller
12{
13 public function action_420()
14 {
15 $configs = [
16 [
17 'config_key' => 'razorpay_key_id',
18 'group_name' => 'payment',
19 'config_value' => '',
20 ],
21 [
22 'config_key' => 'razorpay_key_secret',
23 'group_name' => 'payment',
24 'config_value' => '0',
25 ],
26 [
27 'config_key' => 'stripe_ideal',
28 'group_name' => 'payment',
29 'config_value' => '0',
30 ],
31 [
32 'config_key' => 'sms_service',
33 'group_name' => 'general',
34 'config_value' => 'clickatell',
35 ],
36 [
37 'config_key' => 'sms_2factorin_api',
38 'group_name' => 'general',
39 'config_value' => '',
40 ],
41 [
42 'config_key' => 'sms_2factorin_sender_id',
43 'group_name' => 'general',
44 'config_value' => '',
45 ],
46 [
47 'config_key' => 'sms_2factorin_subscription_payment_template',
48 'group_name' => 'general',
49 'config_value' => '',
50 ],
51 [
52 'config_key' => 'sms_2factorin_expiring_subscription_template',
53 'group_name' => 'general',
54 'config_value' => '',
55 ],
56 [
57 'config_key' => 'sms_2factorin_featured_ad_payment_template',
58 'group_name' => 'general',
59 'config_value' => '',
60 ],
61 [
62 'config_key' => 'subscriptions_expire_dont_limit_access',
63 'group_name' => 'general',
64 'config_value' => '0',
65 ],
66 [
67 'config_key' => 'analytics_global_site_tag',
68 'group_name' => 'general',
69 'config_value' => '',
70 ],
71 [
72 'config_key' => 'stripe_connect_legacy',
73 'group_name' => 'payment',
74 'config_value' => '1',
75 ],
76 [
77 'config_key' => 'stripe_escrow',
78 'group_name' => 'payment',
79 'config_value' => '0',
80 ],
81 [
82 'config_key' => 'stripe_cancel_orders_after_n_days',
83 'group_name' => 'payment',
84 'config_value' => '30',
85 ],
86 [
87 'config_key' => 'stripe_appfee_fixed',
88 'group_name' => 'payment',
89 'config_value' => '0',
90 ],
91 [
92 'config_key' => 'stripe_connected_account_mandatory',
93 'group_name' => 'payment',
94 'config_value' => '0',
95 ],
96 ];
97
98 Model_Config::config_array($configs);
99
100 // Crontabs
101 try {
102 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
103 ('About to Expire Subscription', '05 9 * * *', 'Cron_Subscription::to_expire', NULL, 'Notify by sms your subscription is about to expire', 1),
104 ('Mark unshipped orders as cancelled', '0 11 * * *', 'Cron_Ad::mark_as_cancelled', NULL, 'Mark unshipped orders as cancelled n days after was paid', 1);")->execute();
105 } catch (exception $e) {
106 }
107
108 // Shipping tracking code
109 try {
110 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `shipping_tracking_code` VARCHAR(255) DEFAULT NULL;")->execute();
111 } catch (exception $e) {
112 }
113
114 // Shipping provider name
115 try {
116 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `shipping_provider_name` VARCHAR(140) DEFAULT NULL;")->execute();
117 } catch (exception $e) {
118 }
119
120 // Mark orders as shipped
121 try {
122 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `shipped` DATETIME NULL DEFAULT NULL;")->execute();
123 } catch (exception $e) {
124 }
125
126 // Mark orders as cancelled
127 try {
128 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `cancelled` DATETIME NULL DEFAULT NULL;")->execute();
129 } catch (exception $e) {
130 }
131
132 // Mark orders as paid out
133 try {
134 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `paid_out` DATETIME NULL DEFAULT NULL;")->execute();
135 } catch (exception $e) {
136 }
137
138 // new emails
139 $contents = [
140 [
141 'order' => 0,
142 'title' => 'Order shipped for [ORDER.DESC] #[ORDER.ID]',
143 'seotitle' => 'order-shipped',
144 'description' => "Hello [USER.NAME],\n\nThanks for buying [ORDER.DESC].\n\nYour order has been shipped.\n\nTracking code [ORDER.SHIPPING_PROVIDER_NAME] [ORDER.SHIPPING_TRACKING_CODE] [URL.QL]",
145 'from_email' => core::config('email.notify_email'),
146 'type' => 'email',
147 'status' => '1',
148 ],
149 [
150 'order' => 0,
151 'title' => 'Order cancelled for [ORDER.DESC] #[ORDER.ID]',
152 'seotitle' => 'order-cancelled',
153 'description' => "Hello [USER.NAME],\n\nYour order has been cancelled.",
154 'from_email' => core::config('email.notify_email'),
155 'type' => 'email',
156 'status' => '1',
157 ],
158 [
159 'order' => 0,
160 'title' => 'Safe payment request for [AD.NAME]',
161 'seotitle' => 'safe-payment-requested',
162 'description' => "Hello [USER.NAME],\n\nYour ad [AD.NAME] received a safe payment request. Please register with Stripe Connect to receive payments [URL.QL].",
163 'from_email' => core::config('email.notify_email'),
164 'type' => 'email',
165 'status' => '1',
166 ],
167 ];
168
169 Model_Content::content_array($contents);
170 }
171
172 public function action_411()
173 {
174
175 // new indexes
176 try {
177 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."users ADD INDEX IF NOT EXISTS ".self::$db_prefix."users_IK_status (status);")->execute();
178 } catch (exception $e) {
179 }
180
181 try {
182 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."categories ADD INDEX IF NOT EXISTS ".self::$db_prefix."categories_IK_id_category_parent (id_category_parent);")->execute();
183 } catch (exception $e) {
184 }
185
186 try {
187 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."categories ADD INDEX IF NOT EXISTS ".self::$db_prefix."categories_IK_id_category_parent_AND_parent_deep (id_category_parent, parent_deep);")->execute();
188 } catch (exception $e) {
189 }
190
191 try {
192 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."locations ADD INDEX IF NOT EXISTS ".self::$db_prefix."locations_IK_id_location_parent (id_location_parent);")->execute();
193 } catch (exception $e) {
194 }
195
196 try {
197 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."locations ADD INDEX IF NOT EXISTS ".self::$db_prefix."locations_IK_id_location_parent_AND_parent_deep (id_location_parent, parent_deep);")->execute();
198 } catch (exception $e) {
199 }
200
201 }
202
203 public function action_410()
204 {
205 // Transactions
206 try {
207 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."transactions` (
208 `id_transaction` int(10) unsigned NOT NULL AUTO_INCREMENT,
209 `id_user` int(10) unsigned DEFAULT NULL,
210 `id_user_from` int(10) unsigned DEFAULT NULL,
211 `id_order` int(10) unsigned DEFAULT NULL,
212 `amount` int(10) NOT NULL,
213 `type` tinyint(1) NOT NULL DEFAULT 0,
214 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
215 PRIMARY KEY (`id_transaction`),
216 KEY `".self::$db_prefix."transactions_IK_id_user` (`id_user`),
217 KEY `".self::$db_prefix."transactions_IK_id_user_from` (`id_user_from`),
218 KEY `".self::$db_prefix."transactions_IK_id_order` (`id_order`)
219 ) ENGINE=InnoDB;")->execute();
220 } catch (exception $e) {
221 }
222
223 // Mark orders as received
224 try {
225 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `received` DATETIME NULL DEFAULT NULL;")->execute();
226 } catch (exception $e) {
227 }
228
229 try {
230 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `ewallet_balance` int(10) unsigned DEFAULT 0")->execute();
231 } catch (exception $e) {
232 }
233
234 $configs = [
235 [
236 'config_key' => 'autodata',
237 'group_name' => 'general',
238 'config_value' => '0'
239 ],
240 [
241 'config_key' => 'subscriptions_mark_as_sold',
242 'group_name' => 'general',
243 'config_value' => '0'
244 ],
245 [
246 'config_key' => 'users_must_verify_email',
247 'group_name' => 'general',
248 'config_value' => '0'
249 ],
250 [
251 'config_key' => 'custom_orders',
252 'group_name' => 'general',
253 'config_value' => '0'
254 ],
255 [
256 'config_key' => 'ewallet',
257 'group_name' => 'general',
258 'config_value' => '0'
259 ],
260 [
261 'config_key' => 'ewallet_money_symbol',
262 'group_name' => 'general',
263 'config_value' => '$'
264 ],
265 [
266 'config_key' => 'ewallet_add_money',
267 'group_name' => 'general',
268 'config_value' => '0'
269 ],
270 [
271 'config_key' =>'ewallet_money_packages',
272 'group_name' =>'general',
273 'config_value' => '{"1000":"10"}'
274 ],
275 [
276 'config_key' =>'ewallet_gamification',
277 'group_name' =>'general',
278 'config_value' => '0'
279 ],
280 [
281 'config_key' =>'ewallet_gamification_earn_on_sign_up',
282 'group_name' =>'general',
283 'config_value' => ''
284 ],
285 [
286 'config_key' =>'ewallet_mark_as_received_reminder_after_n_days',
287 'group_name' =>'general',
288 'config_value' => '7'
289 ],
290 [
291 'config_key' =>'ewallet_mark_as_received_after_n_days',
292 'group_name' =>'general',
293 'config_value' => '14'
294 ],
295 ];
296
297 // Crontabs
298 try {
299 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
300 ('Unreceived orders reminder', '0 10 * * *', 'Cron_Ad::unreceived', NULL, 'Email reminder of unreceived orders n days after was paid', 1),
301 ('Mark unreceived orders as received', '0 11 * * *', 'Cron_Ad::mark_as_received', NULL, 'Mark unreceived orders as received n days after was paid', 1);")->execute();
302 } catch (exception $e) {
303 }
304
305 // User email varification code
306 try {
307 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `verification_code` int(6) DEFAULT NULL")->execute();
308 } catch (exception $e) {
309 }
310
311 Model_Config::config_array($configs);
312
313 // new emails
314 $contents = [
315 [
316 'order' => 0,
317 'title' => 'Welcome to [SITE.NAME]!',
318 'seotitle' => 'auth-verify-email',
319 'description' => "Welcome [USER.NAME],\n\nWe are really happy that you have joined us!\nPlease click on this link [URL.QL] to confirm your email\n\nRemember your user details:\nEmail: [USER.EMAIL]\nPassword: [USER.PWD]\n\nWe do not have your original password anymore.\n\nRegards!",
320 'from_email' => core::config('email.notify_email'),
321 'type' => 'email',
322 'status' => '1',
323 ],
324 [
325 'order' => 0,
326 'title' => 'Mark as received reminder for [ORDER.DESC] #[ORDER.ID]',
327 'seotitle' => 'mark-as-received',
328 'description' => "Hello [USER.NAME],Thanks for buying [ORDER.DESC].\n\nPlease mark it as received here [URL.CHECKOUT]",
329 'from_email' => core::config('email.notify_email'),
330 'type' => 'email',
331 'status' => '1',
332 ],
333 ];
334
335 Model_Content::content_array($contents);
336
337 // eWallet access
338 try {
339 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."access` (`id_role`, `access`) VALUES
340 (1, 'ewallet.*'),(5, 'ewallet.*'),(7, 'ewallet.*')")->execute();
341 } catch (exception $e) {
342 }
343 }
344
345 public function action_400()
346 {
347 //fixes yahoo login
348 try {
349 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."config` SET `config_value`= REPLACE(`config_value`,',\"Yahoo\":{\"enabled\":\"0\",\"keys\":{\"key\":',',\"Yahoo\":{\"enabled\":\"0\",\"keys\":{\"id\":') WHERE `group_name` = 'social' AND `config_key`='config' AND `config_value` LIKE '%,\"Yahoo\":{\"enabled\":\"0\",\"keys\":{\"key\":%'")->execute();
350 } catch (exception $e) {
351 }
352
353 if (Core::config('appearance.theme') == 'default') {
354 Model_Config::set_value('appearance', 'theme', 'atlantic-lite');
355 }
356 }
357
358 public function action_380()
359 {
360 $configs = array(
361 array( 'config_key' => 'cloudinary_api_key',
362 'group_name' => 'advertisement',
363 'config_value' => ''),
364 array( 'config_key' => 'cloudinary_api_secret',
365 'group_name' => 'advertisement',
366 'config_value' => ''),
367 array( 'config_key' => 'cloudinary_cloud_name',
368 'group_name' => 'advertisement',
369 'config_value' => ''),
370 array( 'config_key' => 'cloudinary_cloud_preset',
371 'group_name' => 'advertisement',
372 'config_value' => ''),
373 array( 'config_key' => 'sms_clickatell_two_way_phone',
374 'group_name' => 'general',
375 'config_value' => ''),
376 array( 'config_key' => 'mailgun_api_key',
377 'group_name' => 'email',
378 'config_value' => ''),
379 array( 'config_key' => 'mailgun_domain',
380 'group_name' => 'email',
381 'config_value' => ''),
382 );
383
384 Model_Config::config_array($configs);
385 }
386
387 public function action_370()
388 { //new configs
389 $configs = array(
390 array(
391 'config_key' => 'recaptcha_type',
392 'group_name' => 'general',
393 'config_value' => 'checkbox',
394 ),
395 array(
396 'config_key' => 'escrow_sandbox',
397 'group_name' => 'payment',
398 'config_value' => '0',
399 ),
400 array(
401 'config_key' => 'escrow_pay',
402 'group_name' => 'payment',
403 'config_value' => '0',
404 ),
405 array(
406 'config_key' => 'stripe_legacy',
407 'group_name' => 'payment',
408 'config_value' => '1',
409 ),
410 array(
411 'config_key' => 'serfinsa_token',
412 'group_name' => 'payment',
413 'config_value' => '',
414 ),
415 array(
416 'config_key' => 'serfinsa_sandbox',
417 'group_name' => 'payment',
418 'config_value' => '0',
419 ),
420 array(
421 'config_key' => 'add_to_home_screen',
422 'group_name' => 'general',
423 'config_value' => '0',
424 ),
425 );
426
427 Model_Config::config_array($configs);
428
429 //escrow pay
430 try {
431 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `escrow_email` varchar(140) DEFAULT NULL")->execute();
432 } catch (exception $e) {
433 }
434
435 try {
436 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `escrow_api_key` varchar(140) DEFAULT NULL")->execute();
437 } catch (exception $e) {
438 }
439
440 //escrow access
441 try {
442 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."access` (`id_role`, `access`) VALUES
443 (1, 'escrow.*'),(5, 'escrow.*'),(7, 'escrow.*')")->execute();
444 } catch (exception $e) {
445 }
446
447 //order quantity
448 try {
449 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `quantity` int NOT NULL DEFAULT '0'")->execute();
450 } catch (exception $e) {
451 }
452
453 //category font icon
454 try {
455 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."categories` ADD `icon_font` varchar(140) DEFAULT NULL")->execute();
456 } catch (exception $e) {
457 }
458
459 //desciption default null
460 try {
461 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` CHANGE `description` `description` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL; ")->execute();
462 } catch (exception $e) {
463 }
464 }
465
466 public function action_360()
467 { //new configs
468 $configs = array(
469 array( 'config_key' => 'banned_words_among',
470 'group_name' => 'advertisement',
471 'config_value' => '0'),
472 );
473
474 Model_Config::config_array($configs);
475
476 //mylistings access
477 try {
478 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."access` (`id_role`, `access`) VALUES
479 (1, 'mylistings.*'),(5, 'mylistings.*'),(7, 'mylistings.*')")->execute();
480 } catch (exception $e) {
481 }
482 }
483
484 public function action_350()
485 {
486 //new configs
487 $configs = array(
488
489 array( 'config_key' => 'vat_non_eu',
490 'group_name' => 'payment',
491 'config_value' => ''),
492 array( 'config_key' => 'bitpay_pairing_code',
493 'group_name' => 'payment',
494 'config_value' => ''),
495 array( 'config_key' => 'bitpay_token',
496 'group_name' => 'payment',
497 'config_value' => ''),
498 array( 'config_key' => 'bitpay_sandbox',
499 'group_name' => 'payment',
500 'config_value' => '0'),
501 array( 'config_key' => 'bitpay_private_key',
502 'group_name' => 'payment',
503 'config_value' => ''),
504 array( 'config_key' => 'bitpay_public_key',
505 'group_name' => 'payment',
506 'config_value' => ''),
507 array( 'config_key' => 'disallowed_email_domains',
508 'group_name' => 'general',
509 'config_value' => ''),
510 array( 'config_key' => 'multilingual',
511 'group_name' => 'general',
512 'config_value' => '0'),
513 array( 'config_key' => 'languages',
514 'group_name' => 'general',
515 'config_value' => ''),
516 );
517
518 Model_Config::config_array($configs);
519
520 try {
521 DB::query(Database::UPDATE, 'ALTER TABLE `' . self::$db_prefix . 'ads` ADD `locale` VARCHAR(5) DEFAULT NULL')->execute();
522 } catch (exception $e) {
523 }
524
525 try {
526 DB::query(Database::UPDATE, 'ALTER TABLE `' . self::$db_prefix . 'categories` ADD `translations` TEXT DEFAULT NULL')->execute();
527 } catch (exception $e) {
528 }
529
530 try {
531 DB::query(Database::UPDATE, 'ALTER TABLE `' . self::$db_prefix . 'locations` ADD `translations` TEXT DEFAULT NULL')->execute();
532 } catch (exception $e) {
533 }
534
535 if (array_key_exists('longitute', Database::instance()->list_columns('users'))) {
536 try {
537 DB::query(Database::UPDATE, 'ALTER TABLE ' . self::$db_prefix . 'users CHANGE COLUMN `longitute` `longitude` float(10,6) DEFAULT NULL;')->execute();
538 } catch (exception $e) {
539 }
540 }
541 }
542
543 public function action_340()
544 {
545 //new configs
546 $configs = array(
547
548 array( 'config_key' => 'zenith_testing',
549 'group_name' => 'payment',
550 'config_value' => '0'),
551 array( 'config_key' => 'zenith_merchantid',
552 'group_name' => 'payment',
553 'config_value' => ''),
554 array( 'config_key' => 'zenith_uid',
555 'group_name' => 'payment',
556 'config_value' => ''),
557 array( 'config_key' => 'zenith_pwd',
558 'group_name' => 'payment',
559 'config_value' => ''),
560 array( 'config_key' => 'zenith_merchant_name',
561 'group_name' => 'payment',
562 'config_value' => ''),
563 array( 'config_key' => 'zenith_merchant_phone',
564 'group_name' => 'payment',
565 'config_value' => ''),
566 array( 'config_key' => 'carquery',
567 'group_name' => 'general',
568 'config_value' => '0'),
569 array( 'config_key' => 'payline_testing',
570 'group_name' => 'payment',
571 'config_value' => '0'),
572 array( 'config_key' => 'payline_merchant_id',
573 'group_name' => 'payment',
574 'config_value' => ''),
575 array( 'config_key' => 'payline_access_key',
576 'group_name' => 'payment',
577 'config_value' => ''),
578 array( 'config_key' => 'payline_contract_number',
579 'group_name' => 'payment',
580 'config_value' => ''),
581 array( 'config_key' => 'oauth2_enabled',
582 'group_name' => 'social',
583 'config_value' => 0),
584 array( 'config_key' => 'oauth2_client_id',
585 'group_name' => 'social',
586 'config_value' => ''),
587 array( 'config_key' => 'oauth2_client_secret',
588 'group_name' => 'social',
589 'config_value' => ''),
590 array( 'config_key' => 'oauth2_url_authorize',
591 'group_name' => 'social',
592 'config_value' => ''),
593 array( 'config_key' => 'oauth2_url_access_token',
594 'group_name' => 'social',
595 'config_value' => ''),
596 array( 'config_key' => 'oauth2_url_resource_owner_details',
597 'group_name' => 'social',
598 'config_value' => ''),
599 array( 'config_key' => 'homepage_map',
600 'group_name' => 'advertisement',
601 'config_value' => '0'),
602 array( 'config_key' => 'homepage_map_height',
603 'group_name' => 'advertisement',
604 'config_value' => ''),
605 array( 'config_key' => 'homepage_map_allowfullscreen',
606 'group_name' => 'advertisement',
607 'config_value' => '1'),
608 );
609
610
611
612 Model_Config::config_array($configs);
613
614 try {
615 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `latitude` float(10,6) DEFAULT NULL")->execute();
616 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `longitude` float(10,6) DEFAULT NULL")->execute();
617 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `address` varchar(145) DEFAULT NULL")->execute();
618 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;")->execute();
619 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` CHANGE `price` `price` DECIMAL(28,8) NOT NULL DEFAULT '0.000'")->execute();
620 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."categories` CHANGE `price` `price` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
621 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` CHANGE `amount` `amount` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
622 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."subscribers` CHANGE `min_price` `min_price` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
623 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."subscribers` CHANGE `max_price` `max_price` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
624 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."messages` CHANGE `price` `price` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
625 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."coupons` CHANGE `discount_amount` `discount_amount` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
626 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."coupons` CHANGE `discount_percentage` `discount_percentage` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
627 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."plans` CHANGE `price` `price` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
628 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."plans` CHANGE `marketplace_fee` `marketplace_fee` DECIMAL(28,8) NOT NULL DEFAULT '0'")->execute();
629 } catch (exception $e) {
630 }
631
632
633 //delete bitcoin from stripe
634 try {
635 DB::query(Database::DELETE, "DELETE FROM ".self::$db_prefix."config WHERE `config_key` = 'stripe_bitcoin'")->execute();
636 } catch (exception $e) {
637 }
638
639 File::replace_file(APPPATH.'config/database.php', "'utf8'", "'utf8mb4'");
640 }
641
642 public function action_330()
643 {
644 //new configs
645 $configs = array(
646
647 array( 'config_key' => 'subscriptions_expire',
648 'group_name' => 'general',
649 'config_value' => '0'),
650 array( 'config_key' => 'pusher_notifications_cluster',
651 'group_name' => 'general',
652 'config_value' => 'eu'),
653 array( 'config_key' => 'sms_auth',
654 'group_name' => 'general',
655 'config_value' => '0'),
656 array( 'config_key' => 'sms_clickatell_api',
657 'group_name' => 'general',
658 'config_value' => ''),
659 array( 'config_key' => 'login_to_view_ad',
660 'group_name' => 'advertisement',
661 'config_value' => 0),
662 array( 'config_key' => 'delete_ad',
663 'group_name' => 'advertisement',
664 'config_value' => 0),
665 array( 'config_key' => 'upload_from_url',
666 'group_name' => 'image',
667 'config_value' => 0),
668 array( 'config_key' => 'country',
669 'group_name' => 'general',
670 'config_value' => ''),
671 );
672
673 Model_Config::config_array($configs);
674
675 //user phone number
676 try {
677 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `phone` varchar(30) DEFAULT NULL")->execute();
678 } catch (exception $e) {
679 }
680 }
681
682 public function action_320()
683 {
684 File::delete(DOCROOT.'oc/classes/database/mysqli');
685 File::delete(DOCROOT.'oc/classes/database/query.php');
686 File::delete(DOCROOT.'oc/classes/image');
687 File::delete(DOCROOT.'oc/common');
688
689
690 $email_service = (Core::config('email.elastic_active') == 1 ? 'elastic': (Core::config('email.smtp_active') == 1?'smtp':'mail'));
691
692 //new configs
693 $configs = array(
694 array( 'config_key' => 'service',
695 'group_name' => 'email',
696 'config_value' => $email_service),
697 array( 'config_key' => 'instagram',
698 'group_name' => 'advertisement',
699 'config_value' => '0'),
700 array( 'config_key' => 'instagram_username',
701 'group_name' => 'advertisement',
702 'config_value' => ''),
703 array( 'config_key' => 'instagram_password',
704 'group_name' => 'advertisement',
705 'config_value' => ''),
706 array( 'config_key' => 'pinterest',
707 'group_name' => 'advertisement',
708 'config_value' => '0'),
709 array( 'config_key' => 'pinterest_app_id',
710 'group_name' => 'advertisement',
711 'config_value' => ''),
712 array( 'config_key' => 'pinterest_app_secret',
713 'group_name' => 'advertisement',
714 'config_value' => ''),
715 array( 'config_key' => 'pinterest_access_token',
716 'group_name' => 'advertisement',
717 'config_value' => ''),
718 array( 'config_key' => 'pinterest_board',
719 'group_name' => 'advertisement',
720 'config_value' => ''),
721 array( 'config_key' => 'paytabs_merchant_email',
722 'group_name' => 'payment',
723 'config_value' => ''),
724 array( 'config_key' => 'paytabs_secret_key',
725 'group_name' => 'payment',
726 'config_value' => ''),
727 array( 'config_key' => 'payfast_merchant_id',
728 'group_name' => 'payment',
729 'config_value' => ''),
730 array( 'config_key' => 'payfast_merchant_key',
731 'group_name' => 'payment',
732 'config_value' => ''),
733 array( 'config_key' => 'payfast_sandbox',
734 'group_name' => 'payment',
735 'config_value' => '0'),
736 array( 'config_key' => 'pusher_notifications',
737 'group_name' => 'general',
738 'config_value' => '0'),
739 array( 'config_key' => 'pusher_notifications_app_id',
740 'group_name' => 'general',
741 'config_value' => ''),
742 array( 'config_key' => 'pusher_notifications_key',
743 'group_name' => 'general',
744 'config_value' => ''),
745 array( 'config_key' => 'pusher_notifications_secret',
746 'group_name' => 'general',
747 'config_value' => ''),
748 array( 'config_key' => 'algolia_search',
749 'group_name' => 'general',
750 'config_value' => '0'),
751 array( 'config_key' => 'algolia_search_application_id',
752 'group_name' => 'general',
753 'config_value' => ''),
754 array( 'config_key' => 'algolia_search_admin_key',
755 'group_name' => 'general',
756 'config_value' => ''),
757 array( 'config_key' => 'algolia_search_only_key',
758 'group_name' => 'general',
759 'config_value' => ''),
760 array( 'config_key' => 'algolia_powered_by_enabled',
761 'group_name' => 'general',
762 'config_value' => '1'),
763 );
764
765 Model_Config::config_array($configs);
766
767 //modify only the plans that are wrong
768 try {
769 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."plans SET id_plan=id_plan+100 WHERE id_plan < 100")->execute();
770 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."plans` AUTO_INCREMENT=100")->execute();
771 } catch (exception $e) {
772 }
773
774 //crontab re-index algolia indices
775 try {
776 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
777 ('Algolia Search re-index', '0 * * * *', 'Cron_Algolia::reindex', NULL, 'Re-index everything', 1);")->execute();
778 } catch (exception $e) {
779 }
780 }
781
782
783 /**
784 * This function will upgrade DB that didn't existed in versions prior to 3.1.0
785 */
786 public function action_310()
787 {
788 //new configs
789 $configs = array(
790 array( 'config_key' => 'elastic_listname',
791 'group_name' => 'email',
792 'config_value' => ''),
793 array( 'config_key' => 'dropbox_app_key',
794 'group_name' => 'advertisement',
795 'config_value' => ''),
796 array( 'config_key' => 'expire_reactivation',
797 'group_name' => 'advertisement',
798 'config_value' => '1'),
799 array( 'config_key' => 'social_post_only_featured',
800 'group_name' => 'advertisement',
801 'config_value' => ''),
802 array( 'config_key' => 'twitter_consumer_key',
803 'group_name' => 'advertisement',
804 'config_value' => ''),
805 array( 'config_key' => 'twitter_consumer_secret',
806 'group_name' => 'advertisement',
807 'config_value' => ''),
808 array( 'config_key' => 'access_token',
809 'group_name' => 'advertisement',
810 'config_value' => ''),
811 array( 'config_key' => 'access_token_secret',
812 'group_name' => 'advertisement',
813 'config_value' => ''),
814 array( 'config_key' => 'twitter',
815 'group_name' => 'advertisement',
816 'config_value' => '0'),
817 array( 'config_key' => 'facebook_app_id',
818 'group_name' => 'advertisement',
819 'config_value' => ''),
820 array( 'config_key' => 'facebook_app_secret',
821 'group_name' => 'advertisement',
822 'config_value' => ''),
823 array( 'config_key' => 'facebook_access_token',
824 'group_name' => 'advertisement',
825 'config_value' => ''),
826 array( 'config_key' => 'facebook',
827 'group_name' => 'advertisement',
828 'config_value' => '0'),
829 array( 'config_key' => 'facebook_id',
830 'group_name' => 'advertisement',
831 'config_value' => ''),
832 array( 'config_key' => 'picker_api_key',
833 'group_name' => 'advertisement',
834 'config_value' => ''),
835 array( 'config_key' => 'picker_client_id',
836 'group_name' => 'advertisement',
837 'config_value' => ''),
838 );
839
840 Model_Config::config_array($configs);
841
842 //crontab generate FB access token
843 try {
844 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
845 ('Generate Access Token', '10 9 1 * *', 'Social::GetAccessToken', NULL, 'Generate Facebook long-lived Access Token.', 1);")->execute();
846 } catch (exception $e) {
847 }
848
849 //visits table tmp
850 try {
851 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS ".self::$db_prefix."visits_tmp (
852 id_visit int(10) unsigned NOT NULL AUTO_INCREMENT,
853 id_ad int(10) unsigned DEFAULT NULL,
854 hits int(10) NOT NULL DEFAULT '0',
855 contacts int(10) NOT NULL DEFAULT '0',
856 created DATE NOT NULL,
857 PRIMARY KEY (id_visit),
858 UNIQUE KEY ".self::$db_prefix."visits_IK_id_ad_AND_created (id_ad,created)
859 ) ENGINE=InnoDB;")->execute();
860 } catch (exception $e) {
861 }
862
863 //move to tempo table
864 try {
865 DB::query(Database::UPDATE, "INSERT INTO ".self::$db_prefix."visits_tmp (id_ad, hits, contacts, created)
866 SELECT id_ad, count(id_ad) hits,sum(contacted) contacts, DATE(created) created
867 FROM ".self::$db_prefix."visits
868 GROUP BY id_ad, DATE(created)
869 HAVING hits>0
870 ORDER BY DATE(created) ASC;")->execute();
871 } catch (exception $e) {
872 }
873
874 //rename tables, we keep old one...just in case!
875 try {
876 DB::query(Database::UPDATE, "RENAME TABLE ".self::$db_prefix."visits TO ".self::$db_prefix."visits_old;")->execute();
877 } catch (exception $e) {
878 }
879
880 try {
881 DB::query(Database::UPDATE, "RENAME TABLE ".self::$db_prefix."visits_tmp TO ".self::$db_prefix."visits;")->execute();
882 } catch (exception $e) {
883 }
884 }
885
886 /**
887 * This function will upgrade DB that didn't existed in versions prior to 3.1.0
888 */
889 public function action_300()
890 {
891 //new configs
892 $configs = array(
893
894 array( 'config_key' => 'hide_homepage_categories',
895 'group_name' => 'general',
896 'config_value' => '{}'),
897 array( 'config_key' => 'paguelofacil_cclw',
898 'group_name' => 'payment',
899 'config_value' => ''),
900 array( 'config_key' => 'paguelofacil_testing',
901 'group_name' => 'payment',
902 'config_value' => '0'),
903 array( 'config_key' => 'mercadopago_client_id',
904 'group_name' => 'payment',
905 'config_value' => ''),
906 array( 'config_key' => 'mercadopago_client_secret',
907 'group_name' => 'payment',
908 'config_value' => ''),
909 array( 'config_key' => 'contact_price',
910 'group_name' => 'advertisement',
911 'config_value' => '1'),
912 array( 'config_key' => 'report',
913 'group_name' => 'advertisement',
914 'config_value' => '1'),
915 array( 'config_key' => 'stripe_3d_secure',
916 'group_name' => 'payment',
917 'config_value' => '0'),
918 array( 'config_key' => 'vat_country',
919 'group_name' => 'payment',
920 'config_value' => ''),
921 array( 'config_key' => 'vat_number',
922 'group_name' => 'payment',
923 'config_value' => ''),
924 );
925
926 //get theme license and add it to the config
927 if (Theme::get('license')!==null) {
928 $configs[]= array( 'config_key' => 'date',
929 'group_name' => 'license',
930 'config_value' => Theme::get('license_date')
931 );
932
933 $configs[]= array( 'config_key' => 'number',
934 'group_name' => 'license',
935 'config_value' => Theme::get('license')
936 );
937 }
938
939 try {
940 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET description='Hello Admin,\n\n [EMAIL.SENDER]: [EMAIL.FROM], have a message for you:\n\n [EMAIL.SUBJECT]\n\n [EMAIL.BODY] \n\n Regards!' WHERE seotitle='contact-admin'")->execute();
941 } catch (exception $e) {
942 }
943
944 //crontab renew subscription
945 try {
946 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
947 ('Notify new updates', '0 9 * * 1', 'Cron_Update::notify', NULL, 'Notify by email of new site updates.', 1);")->execute();
948 } catch (exception $e) {
949 }
950
951 //stripe agreement
952 try {
953 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `stripe_agreement` varchar(40) DEFAULT NULL")->execute();
954 } catch (exception $e) {
955 }
956
957 //VAT
958 try {
959 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `VAT` varchar(20) DEFAULT NULL")->execute();
960 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `VAT_country` varchar(20) DEFAULT NULL")->execute();
961 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `VAT_number` varchar(20) DEFAULT NULL")->execute();
962 } catch (exception $e) {
963 }
964
965 Model_Config::config_array($configs);
966 }
967
968 /**
969 * This function will upgrade DB that didn't existed in versions prior to 2.9.0
970 */
971 public function action_290()
972 {
973
974 //new configs
975 $configs = array(
976
977 array( 'config_key' => 'robokassa_login',
978 'group_name' => 'payment',
979 'config_value' => ''),
980 array( 'config_key' => 'robokassa_pass1',
981 'group_name' => 'payment',
982 'config_value' => ''),
983 array( 'config_key' => 'robokassa_pass2',
984 'group_name' => 'payment',
985 'config_value' => ''),
986 array( 'config_key' => 'robokassa_testing',
987 'group_name' => 'payment',
988 'config_value' => '0'),
989 array( 'config_key' => 'notify_name',
990 'group_name' => 'email',
991 'config_value' => 'no-reply '.core::config('general.site_name')),
992 );
993
994 //adds Vkontakte login
995 try {
996 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."config` SET `config_value`= REPLACE(`config_value`,'},\"base_url\"',',\"Vkontakte\":{\"enabled\":\"0\",\"keys\":{\"id\":\"\",\"secret\":\"\"}}},\"base_url\"') WHERE `group_name` = 'social' AND `config_key`='config'")->execute();
997 } catch (exception $e) {
998 }
999
1000 Model_Config::config_array($configs);
1001 }
1002
1003 /**
1004 * This function will upgrade DB that didn't existed in versions prior to 2.8.0
1005 */
1006 public function action_280()
1007 {
1008 //google 2 step auth
1009 try {
1010 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `google_authenticator` varchar(40) DEFAULT NULL")->execute();
1011 } catch (exception $e) {
1012 }
1013
1014 //fixes yahoo login
1015 try {
1016 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."config` SET `config_value`= REPLACE(`config_value`,',\"Yahoo\":{\"enabled\":\"0\",\"keys\":{\"id\":',',\"Yahoo\":{\"enabled\":\"0\",\"keys\":{\"key\":') WHERE `group_name` = 'social' AND `config_key`='config' AND `config_value` LIKE '%,\"Yahoo\":{\"enabled\":\"0\",\"keys\":{\"id\":%'")->execute();
1017 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."config` SET `config_value`= REPLACE(`config_value`,',\"Yahoo\":{\"enabled\":\"1\",\"keys\":{\"id\":',',\"Yahoo\":{\"enabled\":\"1\",\"keys\":{\"key\":') WHERE `group_name` = 'social' AND `config_key`='config' AND `config_value` LIKE '%,\"Yahoo\":{\"enabled\":\"1\",\"keys\":{\"id\":%'")->execute();
1018 } catch (exception $e) {
1019 }
1020
1021 //new configs
1022 $configs = array(
1023 array( 'config_key' => 'rich_snippets',
1024 'group_name' => 'advertisement',
1025 'config_value' => '0'),
1026 array( 'config_key' => 'google_authenticator',
1027 'group_name' => 'general',
1028 'config_value' => '0'),
1029 array( 'config_key' => 'private_site',
1030 'group_name' => 'general',
1031 'config_value' => '0'),
1032 array( 'config_key' => 'private_site_page',
1033 'group_name' => 'general',
1034 'config_value' => ''),
1035 array( 'config_key' => 'securepay_merchant',
1036 'group_name' => 'payment',
1037 'config_value' => ''),
1038 array( 'config_key' => 'securepay_password',
1039 'group_name' => 'payment',
1040 'config_value' => ''),
1041 array( 'config_key' => 'securepay_testing',
1042 'group_name' => 'payment',
1043 'config_value' => '0'),
1044 array( 'config_key' => 'gm_api_key',
1045 'group_name' => 'advertisement',
1046 'config_value' => ''),
1047 );
1048
1049 Model_Config::config_array($configs);
1050 }
1051
1052 /**
1053 * This function will upgrade DB that didn't existed in versions prior to 2.7.0
1054 */
1055 public function action_270()
1056 {
1057 //plans
1058 try {
1059 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."plans` (
1060 `id_plan` int(10) unsigned NOT NULL AUTO_INCREMENT,
1061 `name` varchar(145) NOT NULL,
1062 `seoname` varchar(145) NOT NULL,
1063 `description` longtext NOT NULL,
1064 `price` decimal(14,3) NOT NULL DEFAULT '0',
1065 `days` int(10) DEFAULT 1,
1066 `amount_ads` int(10) DEFAULT 1,
1067 `marketplace_fee` decimal(14,3) NOT NULL DEFAULT '0',
1068 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1069 `status` tinyint(1) NOT NULL DEFAULT '0',
1070 PRIMARY KEY (`id_plan`),
1071 UNIQUE KEY `".self::$db_prefix."plan_UK_seoname` (`seoname`)
1072 ) ENGINE=MyISAM AUTO_INCREMENT=100;")->execute();
1073 } catch (exception $e) {
1074 }
1075
1076 //subscriptions
1077 try {
1078 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."subscriptions` (
1079 `id_subscription` int(10) unsigned NOT NULL AUTO_INCREMENT,
1080 `id_order` int(10) unsigned NOT NULL,
1081 `id_user` int(10) unsigned NOT NULL,
1082 `id_plan` int(10) unsigned NOT NULL,
1083 `amount_ads` int(10) DEFAULT 1,
1084 `amount_ads_left` int(10) DEFAULT 0,
1085 `expire_date` DATETIME NULL,
1086 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1087 `status` tinyint(1) NOT NULL DEFAULT '0',
1088 PRIMARY KEY (`id_subscription`)
1089 ) ENGINE=MyISAM ;")->execute();
1090 } catch (exception $e) {
1091 }
1092
1093 //crontab renew subscription
1094 try {
1095 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
1096 ('Renew subscription', '*/5 * * * *', 'Cron_Subscription::renew', NULL, 'Notify by email user subscription will expire. Deactivates current subscription', 1);")->execute();
1097 } catch (exception $e) {
1098 }
1099
1100
1101 //SMTP ssl
1102 try {
1103 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."config` (`group_name`, `config_key`, `config_value`) VALUES ('email', 'smtp_secure', (SELECT IF(config_value=0,'','ssl') as config_value FROM `".self::$db_prefix."config`as oconf WHERE `config_key` = 'smtp_ssl' AND `group_name`='email' LIMIT 1) );")->execute();
1104 } catch (exception $e) {
1105 }
1106
1107 try {
1108 DB::query(Database::UPDATE, "DELETE FROM `".self::$db_prefix."config` WHERE `config_key` = 'smtp_ssl' AND `group_name`='email' LIMIT 1;")->execute();
1109 } catch (exception $e) {
1110 }
1111
1112 //stripe connect
1113 try {
1114 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `stripe_user_id` varchar(140) DEFAULT NULL")->execute();
1115 } catch (exception $e) {
1116 }
1117
1118 // update buyer instructions
1119 try {
1120 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."content` SET description=CONCAT(description,'\n\n[BUYER.INSTRUCTIONS]') WHERE `seotitle` = 'ads-purchased' AND `description` NOT LIKE '%[BUYER.INSTRUCTIONS]'")->execute();
1121 } catch (exception $e) {
1122 }
1123
1124 //location.id_geoname column
1125 try {
1126 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` ADD `id_geoname` int(10) UNSIGNED NULL DEFAULT NULL")->execute();
1127 } catch (exception $e) {
1128 }
1129
1130 //location.fcodename_geoname column
1131 try {
1132 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` ADD `fcodename_geoname` varchar(140) NULL DEFAULT NULL")->execute();
1133 } catch (exception $e) {
1134 }
1135
1136 //new configs
1137 $configs = array(
1138
1139 array( 'config_key' => 'stripe_bitcoin',
1140 'group_name' => 'payment',
1141 'config_value' => '0'),
1142 array( 'config_key' => 'stripe_appfee',
1143 'group_name' => 'payment',
1144 'config_value' => '0'),
1145 array( 'config_key' => 'stripe_connect',
1146 'group_name' => 'payment',
1147 'config_value' => '0'),
1148 array( 'config_key' => 'stripe_clientid',
1149 'group_name' => 'payment',
1150 'config_value' => ''),
1151 array( 'config_key' => 'free',
1152 'group_name' => 'advertisement',
1153 'config_value' => '0'),
1154 array( 'config_key' => 'subscriptions',
1155 'group_name' => 'general',
1156 'config_value' => '0'),
1157 );
1158
1159 Model_Config::config_array($configs);
1160
1161 //new mails
1162 $contents = array(array('order'=>0,
1163 'title'=>'There is a new reply on the forum',
1164 'seotitle'=>'new-forum-answer',
1165 'description'=>"There is a new reply on a forum post where you participated.<br><br><a target=\"_blank\" href=\"[FORUM.LINK]\">Check it here</a><br><br>[FORUM.LINK]<br>",
1166 'from_email'=>core::config('email.notify_email'),
1167 'type'=>'email',
1168 'status'=>'1'),
1169 array('order'=>0,
1170 'title'=>'Your plan [PLAN.NAME] has expired',
1171 'seotitle'=>'plan-expired',
1172 'description'=>"Hello [USER.NAME],Your plan [PLAN.NAME] has expired \n\nPlease renew your plan here [URL.CHECKOUT]",
1173 'from_email'=>core::config('email.notify_email'),
1174 'type'=>'email',
1175 'status'=>'1'),
1176 );
1177
1178 Model_Content::content_array($contents);
1179 }
1180
1181 /**
1182 * This function will upgrade DB that didn't existed in versions prior to 2.6.1
1183 */
1184 public function action_261()
1185 {
1186 //remove innodb
1187 try {
1188 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` DROP FOREIGN KEY `".self::$db_prefix."ads_FK_id_user_AT_users`")->execute();
1189 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` DROP FOREIGN KEY `".self::$db_prefix."ads_FK_id_category_AT_categories`")->execute();
1190 } catch (exception $e) {
1191 }
1192 try {
1193 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` ENGINE = MyISAM")->execute();
1194 } catch (exception $e) {
1195 }
1196 try {
1197 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` ENGINE = MyISAM")->execute();
1198 } catch (exception $e) {
1199 }
1200 try {
1201 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."categories` ENGINE = MyISAM")->execute();
1202 } catch (exception $e) {
1203 }
1204 try {
1205 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ENGINE = MyISAM")->execute();
1206 } catch (exception $e) {
1207 }
1208
1209
1210 //new configs
1211 $configs = array(
1212 array( 'config_key' => 'email_domains',
1213 'group_name' => 'general',
1214 'config_value' => ''),
1215 array( 'config_key' => 'cron',
1216 'group_name' => 'general',
1217 'config_value' => '0'),
1218 array( 'config_key' => 'paysbuy',
1219 'group_name' => 'payment',
1220 'config_value' => ''),
1221 array( 'config_key' => 'paysbuy_sandbox',
1222 'group_name' => 'payment',
1223 'config_value' => '0'),
1224 array( 'config_key' => 'validate_banned_words',
1225 'group_name' => 'advertisement',
1226 'config_value' => '0'),
1227 );
1228
1229 Model_Config::config_array($configs);
1230 }
1231
1232 /**
1233 * This function will upgrade DB that didn't existed in versions prior to 2.6.0
1234 */
1235 public function action_260()
1236 {
1237 //Cron update
1238 try {
1239 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='30 */1 * * *' WHERE callback='Cron_Ad::expired_featured' LIMIT 1")->execute();
1240 } catch (exception $e) {
1241 }
1242
1243 //improve performance table visits
1244 try {
1245 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."visits` DROP `ip_address`")->execute();
1246 } catch (exception $e) {
1247 }
1248 try {
1249 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."visits` DROP INDEX oc2_visits_IK_id_user")->execute();
1250 } catch (exception $e) {
1251 }
1252
1253 //redo users rates
1254 try {
1255 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."users u SET rate=(SELECT AVG(".self::$db_prefix."reviews.rate) rates
1256 FROM ".self::$db_prefix."reviews
1257 RIGHT JOIN ".self::$db_prefix."ads
1258 USING (id_ad)
1259 WHERE ".self::$db_prefix."ads.id_user = u.id_user AND ".self::$db_prefix."reviews.status = 1
1260 GROUP BY ".self::$db_prefix."reviews.id_ad);")->execute();
1261 } catch (exception $e) {
1262 }
1263
1264 //make posts bigger description
1265 try {
1266 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."posts` CHANGE `description` `description` LONGTEXT;")->execute();
1267 } catch (exception $e) {
1268 }
1269
1270 try {
1271 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."content` CHANGE `description` `description` LONGTEXT;")->execute();
1272 } catch (exception $e) {
1273 }
1274
1275 //bigger configs
1276 try {
1277 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."config` CHANGE `config_value` `config_value` LONGTEXT;")->execute();
1278 } catch (exception $e) {
1279 }
1280
1281 //new configs
1282 $configs = array(
1283 array( 'config_key' => 'description',
1284 'group_name' => 'advertisement',
1285 'config_value' => '1'),
1286 array( 'config_key' => 'social_auth',
1287 'group_name' => 'general',
1288 'config_value' => '1'),
1289 array( 'config_key' => 'map_style',
1290 'group_name' => 'advertisement',
1291 'config_value' => ''),
1292 array( 'config_key' => 'adblock',
1293 'group_name' => 'general',
1294 'config_value' => '0'),
1295 array( 'config_key' => 'stripe_alipay',
1296 'group_name' => 'payment',
1297 'config_value' => '0'),
1298 array( 'config_key' => 'auto_locate_distance',
1299 'group_name' => 'advertisement',
1300 'config_value' => '100'),
1301 );
1302
1303 Model_Config::config_array($configs);
1304 }
1305
1306 /**
1307 * This function will upgrade DB that didn't existed in versions prior to 2.5.1
1308 */
1309 public function action_251()
1310 {
1311 //CF users searchable admin privilege option to false if didnt exists
1312 $cf_users = Model_UserField::get_all();
1313 foreach ($cf_users as $name => $options) {
1314 $modified = false;
1315 if (!isset($options['searchable'])) {
1316 $options['searchable'] = false;
1317 $modified = true;
1318 }
1319 if (!isset($options['admin_privilege'])) {
1320 $options['admin_privilege'] = false;
1321 $modified = true;
1322 }
1323 if ($modified === true) {
1324 $field = new Model_UserField();
1325 $field->update($name, ($options['values'] ? implode(',', $options['values']) : null), $options);
1326 }
1327 }
1328
1329 //change latitude/longitude data type length
1330 try {
1331 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` CHANGE `latitude` `latitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
1332 } catch (exception $e) {
1333 }
1334
1335 try {
1336 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` CHANGE `longitude` `longitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
1337 } catch (exception $e) {
1338 }
1339
1340 try {
1341 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` CHANGE `latitude` `latitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
1342 } catch (exception $e) {
1343 }
1344
1345 try {
1346 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` CHANGE `longitude` `longitude` FLOAT(10, 6) NULL DEFAULT NULL")->execute();
1347 } catch (exception $e) {
1348 }
1349
1350 // set to NULL latitude and longitude ads with longitude and longitude equal to 0
1351 try {
1352 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."ads SET latitude=NULL, longitude=NULL WHERE latitude='0' AND longitude='0'")->execute();
1353 } catch (exception $e) {
1354 }
1355
1356 //messages status
1357 try {
1358 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."messages` ADD `status_to` tinyint(1) NOT NULL DEFAULT '0'")->execute();
1359 } catch (exception $e) {
1360 }
1361
1362 try {
1363 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."messages` ADD `status_from` tinyint(1) NOT NULL DEFAULT '0'")->execute();
1364 } catch (exception $e) {
1365 }
1366
1367 //do something with status to migrate to status_from
1368
1369 try {
1370 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."messages` SET `status_from`=`status` , `status_to`=`status`")->execute();
1371 } catch (exception $e) {
1372 }
1373
1374 try {
1375 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."messages` DROP `status`")->execute();
1376 } catch (exception $e) {
1377 }
1378
1379 //new configs
1380 $configs = array(
1381 array( 'config_key' => 'measurement',
1382 'group_name' => 'general',
1383 'config_value' => 'metric'),
1384 array( 'config_key' => 'leave_alert',
1385 'group_name' => 'advertisement',
1386 'config_value' => '1'),
1387 );
1388
1389 Model_Config::config_array($configs);
1390 }
1391
1392 /**
1393 * This function will upgrade DB that didn't existed in versions prior to 2.5.0
1394 */
1395 public function action_250()
1396 {
1397 //htaccess remove old redirects for API
1398 if (is_writable($htaccess_file = DOCROOT.'.htaccess')) {
1399 //get the entire htaccess
1400 $htaccess = file_get_contents($htaccess_file);
1401
1402 //get from and to we want to delete form the file
1403 $search_header = '# Redirects from 1.x to 2.0.x structure';
1404 $search_footer = '# End redirects';
1405
1406 //its in the file?
1407 if (strpos($htaccess, $search_header)!==false and strpos($htaccess, $search_footer)!==false) {
1408 //get unique lines in an array
1409 $lines = explode(PHP_EOL, $htaccess);
1410
1411 //we remove lines between header and footer
1412 if (is_array($lines) and core::count($lines)>5) {
1413 //which KEY int he array is its of the items?
1414 $header_line = array_search($search_header, $lines);
1415 $footer_line = array_search($search_footer, $lines);
1416
1417 //remove each line....
1418 foreach (range($header_line, $footer_line) as $key => $number) {
1419 unset($lines[$number]);
1420 }
1421
1422 //generate the new file from the array
1423 File::write($htaccess_file, implode(PHP_EOL, $lines));
1424 }//we could get the lines as array
1425 }//end found strings
1426 }//end if is_writable
1427
1428
1429 //new configs
1430 $configs = array(
1431 array( 'config_key' =>'api_key',
1432 'group_name' =>'general',
1433 'config_value' => Text::random('alnum', 32)),
1434 array( 'config_key' =>'twocheckout_sid',
1435 'group_name' =>'payment',
1436 'config_value' => ''),
1437 array( 'config_key' =>'twocheckout_secretword',
1438 'group_name' =>'payment',
1439 'config_value' => ''),
1440 array( 'config_key' =>'twocheckout_sandbox',
1441 'group_name' =>'payment',
1442 'config_value' => 0),
1443 array( 'config_key' =>'messaging',
1444 'group_name' =>'general',
1445 'config_value' => 0),
1446 array( 'config_key' =>'gcm_apikey',
1447 'group_name' =>'general',
1448 'config_value' => ''),
1449 array( 'config_key' =>'fraudlabspro',
1450 'group_name' =>'payment',
1451 'config_value' => ''),
1452 array( 'config_key' =>'contact_page',
1453 'group_name' =>'general',
1454 'config_value' => ''),
1455 array( 'config_key' =>'description_bbcode',
1456 'group_name' =>'advertisement',
1457 'config_value' => '1'),
1458 );
1459
1460 Model_Config::config_array($configs);
1461
1462
1463 //api token
1464 try {
1465 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `api_token` varchar(40) DEFAULT NULL")->execute();
1466 } catch (exception $e) {
1467 }
1468
1469 try {
1470 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD CONSTRAINT `oc2_users_UK_api_token` UNIQUE (`api_token`)")->execute();
1471 } catch (exception $e) {
1472 }
1473
1474 //notification date
1475 try {
1476 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `notification_date` DATETIME NULL DEFAULT NULL ;")->execute();
1477 } catch (exception $e) {
1478 }
1479
1480 //device ID
1481 try {
1482 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `device_id` varchar(255) DEFAULT NULL")->execute();
1483 } catch (exception $e) {
1484 }
1485
1486 //favorited counter
1487 try {
1488 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` ADD `favorited` INT(10) UNSIGNED NOT NULL DEFAULT '0'")->execute();
1489 } catch (exception $e) {
1490 }
1491
1492 //crontab ad to expire
1493 try {
1494 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
1495 ('About to Expire Ad', '05 9 * * *', 'Cron_Ad::to_expire', NULL, 'Notify by email your ad is about to expire', 1);")->execute();
1496 } catch (exception $e) {
1497 }
1498
1499
1500 //new mails
1501 $contents = array(array('order'=>0,
1502 'title'=>'Your ad [AD.NAME] is going to expire',
1503 'seotitle'=>'ad-to-expire',
1504 'description'=>"Hello [USER.NAME],Your ad [AD.NAME] will expire soon \n\nPlease check your ad here [URL.EDITAD]",
1505 'from_email'=>core::config('email.notify_email'),
1506 'type'=>'email',
1507 'status'=>'1'),
1508 array('order'=>0,
1509 'title'=>'Password Changed [SITE.NAME]',
1510 'seotitle'=>'password-changed',
1511 'description'=>"Hello [USER.NAME],\n\nYour password has been changed.\n\nThese are now your user details:\nEmail: [USER.EMAIL]\nPassword: [USER.PWD]\n\nWe do not have your original password anymore.\n\nRegards!",
1512 'from_email'=>core::config('email.notify_email'),
1513 'type'=>'email',
1514 'status'=>'1'),
1515 array('order'=>0,
1516 'title'=>'New reply: [TITLE]',
1517 'seotitle'=>'messaging-reply',
1518 'description'=>'[URL.QL]\n\n[DESCRIPTION]',
1519 'from_email'=>core::config('email.notify_email'),
1520 'type'=>'email',
1521 'status'=>'1'),
1522 array('order'=>0,
1523 'title'=>'[FROM.NAME] sent you a direct message',
1524 'seotitle'=>'messaging-user-contact',
1525 'description'=>'Hello [TO.NAME],\n\n[FROM.NAME] have a message for you:\n\n[DESCRIPTION]\n\n[URL.QL]\n\nRegards!',
1526 'from_email'=>core::config('email.notify_email'),
1527 'type'=>'email',
1528 'status'=>'1'),
1529 array('order'=>0,
1530 'title'=>'Hello [TO.NAME]!',
1531 'seotitle'=>'messaging-ad-contact',
1532 'description'=>'You have been contacted regarding your advertisement:\n\n`[AD.NAME]`.\n\nUser [FROM.NAME], have a message for you:\n\n[DESCRIPTION]\n\n[URL.QL]\n\nRegards!',
1533 'from_email'=>core::config('email.notify_email'),
1534 'type'=>'email',
1535 'status'=>'1'),
1536 );
1537
1538 Model_Content::content_array($contents);
1539
1540 //messages
1541 try {
1542 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS ".self::$db_prefix."messages (
1543 `id_message` int(10) unsigned NOT NULL AUTO_INCREMENT,
1544 `id_ad` int(10) unsigned DEFAULT NULL,
1545 `id_message_parent` int(10) unsigned DEFAULT NULL,
1546 `id_user_from` int(10) unsigned NOT NULL,
1547 `id_user_to` int(10) unsigned NOT NULL,
1548 `message` text NOT NULL,
1549 `price` decimal(14,3) NOT NULL DEFAULT '0',
1550 `read_date` datetime DEFAULT NULL,
1551 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1552 `status` tinyint(1) NOT NULL DEFAULT 0,
1553 PRIMARY KEY (id_message) USING BTREE
1554 ) ENGINE=MyISAM ;")->execute();
1555 } catch (exception $e) {
1556 }
1557
1558
1559 //coupons
1560 try {
1561 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."coupons` (
1562 `id_coupon` int(10) unsigned NOT NULL AUTO_INCREMENT,
1563 `id_product` int(10) unsigned NULL DEFAULT NULL,
1564 `name` varchar(145) NOT NULL,
1565 `notes` varchar(245) DEFAULT NULL,
1566 `discount_amount` decimal(14,3) NOT NULL DEFAULT '0',
1567 `discount_percentage` decimal(14,3) NOT NULL DEFAULT '0',
1568 `number_coupons` int(10) DEFAULT NULL,
1569 `valid_date` DATETIME NULL,
1570 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1571 `status` tinyint(1) NOT NULL DEFAULT '0',
1572 PRIMARY KEY (`id_coupon`),
1573 UNIQUE KEY `".self::$db_prefix."coupons_UK_name` (`name`)
1574 ) ENGINE=MyISAM")->execute();
1575 } catch (exception $e) {
1576 }
1577
1578 try {
1579 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `id_coupon` INT NULL DEFAULT NULL")->execute();
1580 } catch (exception $e) {
1581 }
1582 //end coupons
1583
1584
1585 //myads access
1586 try {
1587 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."access` (`id_role`, `access`) VALUES
1588 (1, 'myads.*'),(5, 'myads.*'),(7, 'myads.*')")->execute();
1589 } catch (exception $e) {
1590 }
1591
1592 //messages access
1593 try {
1594 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."access` (`id_role`, `access`) VALUES
1595 (1, 'messages.*'),(5, 'messages.*'),(7, 'messages.*')")->execute();
1596 } catch (exception $e) {
1597 }
1598
1599 //set favorites count
1600 $ads = new Model_Ad();
1601 $ads = $ads->find_all();
1602
1603 if (core::count($ads)) {
1604 foreach ($ads as $ad) {
1605 $ad->favorited = $ad->favorites->count_all();
1606
1607 try {
1608 $ad->save();
1609 } catch (Exception $e) {
1610 throw HTTP_Exception::factory(500, $e->getMessage());
1611 }
1612 }
1613 }
1614 }
1615
1616 /**
1617 * This function will upgrade DB that didn't existed in versions prior to 2.4.1
1618 */
1619 public function action_241()
1620 {
1621 }
1622
1623 /**
1624 * This function will upgrade DB that didn't existed in versions prior to 2.4.0
1625 */
1626 public function action_240()
1627 {
1628 //new configs
1629 $configs = array(
1630 array( 'config_key' =>'subscribe',
1631 'group_name' =>'general',
1632 'config_value' => 0),
1633 array( 'config_key' =>'cookie_consent',
1634 'group_name' =>'general',
1635 'config_value' => 0),
1636 array( 'config_key' =>'sharing',
1637 'group_name' =>'advertisement',
1638 'config_value' => 0),
1639 array( 'config_key' =>'logbee',
1640 'group_name' =>'advertisement',
1641 'config_value' => 0),
1642 array( 'config_key' =>'thanks_page',
1643 'group_name' =>'advertisement',
1644 'config_value' => ''),
1645 array( 'config_key' =>'auto_locate',
1646 'group_name' =>'general',
1647 'config_value' => 0),
1648 array( 'config_key' =>'search_multi_catloc',
1649 'group_name' =>'general',
1650 'config_value' => 0),
1651 array( 'config_key' =>'featured_plans',
1652 'group_name' =>'payment',
1653 'config_value' => '{"5":"10"}'),
1654 array( 'config_key' =>'user_fields',
1655 'group_name' =>'user',
1656 'config_value' => '{}'),
1657 );
1658
1659 Model_Config::config_array($configs);
1660
1661 //locations latitude/longitude
1662 try {
1663 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` ADD `latitude` DOUBLE NULL , ADD `longitude` DOUBLE NULL ;")->execute();
1664 } catch (exception $e) {
1665 }
1666
1667 //ads latitude/longitude
1668 try {
1669 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` ADD `latitude` DOUBLE NULL , ADD `longitude` DOUBLE NULL ;")->execute();
1670 } catch (exception $e) {
1671 }
1672
1673 //featured days on orders
1674 try {
1675 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `featured_days` int(10) unsigned DEFAULT 0")->execute();
1676 } catch (exception $e) {
1677 }
1678
1679 //update pay as feature, create one in the array
1680 $price = core::config('payment.pay_to_go_on_feature');
1681 $days = core::config('payment.featured_days');
1682
1683 Model_Order::set_featured_plan($days, $price);
1684
1685 Model_Config::set_value('payment', 'pay_to_go_on_feature', 1);
1686 }
1687
1688 /**
1689 * This function will upgrade DB that didn't existed in versions prior to 2.3.1
1690 */
1691 public function action_231()
1692 {
1693 //deleted classes moved to common
1694 File::delete(DOCROOT.'oc/classes/bitpay.php');
1695 File::delete(DOCROOT.'oc/classes/paymill.php');
1696 File::delete(DOCROOT.'oc/classes/stripeko.php');
1697 File::delete(DOCROOT.'themes/default/views/pages/authorize/button.php');
1698 File::delete(DOCROOT.'themes/default/views/pages/bitpay/button_loged.php');
1699 File::delete(DOCROOT.'themes/default/views/pages/paymill/button_loged.php');
1700 }
1701
1702 /**
1703 * This function will upgrade DB that didn't existed in versions prior to 2.3.0
1704 */
1705 public function action_230()
1706 {
1707 //Cron update
1708 try {
1709 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='00 3 * * *' WHERE callback='Sitemap::generate' LIMIT 1")->execute();
1710 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='00 5 * * *' WHERE callback='Core::delete_cache' LIMIT 1")->execute();
1711 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='00 4 1 * *' WHERE callback='Core::optimize_db' LIMIT 1")->execute();
1712 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='00 7 * * *' WHERE callback='Cron_Ad::unpaid' LIMIT 1")->execute();
1713 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='00 8 * * *' WHERE callback='Cron_Ad::expired_featured' LIMIT 1")->execute();
1714 DB::query(Database::UPDATE, "UPDATE `".self::$db_prefix."crontab` SET period='00 9 * * *' WHERE callback='Cron_Ad::expired' LIMIT 1")->execute();
1715 } catch (exception $e) {
1716 }
1717
1718 //control login attempts
1719 try {
1720 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `last_failed` DATETIME NULL DEFAULT NULL ;")->execute();
1721 } catch (exception $e) {
1722 }
1723
1724 try {
1725 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `failed_attempts` int(10) unsigned DEFAULT 0")->execute();
1726 } catch (exception $e) {
1727 }
1728
1729 //categories/locations/users/ads has_image/last_modified
1730 try {
1731 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."categories` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
1732 } catch (exception $e) {
1733 }
1734
1735 try {
1736 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."categories` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
1737 } catch (exception $e) {
1738 }
1739
1740 try {
1741 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
1742 } catch (exception $e) {
1743 }
1744
1745 try {
1746 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
1747 } catch (exception $e) {
1748 }
1749
1750 try {
1751 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
1752 } catch (exception $e) {
1753 }
1754
1755 try {
1756 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
1757 } catch (exception $e) {
1758 }
1759
1760 //new configs
1761 $configs = array(
1762 array( 'config_key' =>'aws_s3_active',
1763 'group_name' =>'image',
1764 'config_value' => 0),
1765 array( 'config_key' =>'aws_access_key',
1766 'group_name' =>'image',
1767 'config_value' =>''),
1768 array( 'config_key' =>'aws_secret_key',
1769 'group_name' =>'image',
1770 'config_value' =>''),
1771 array( 'config_key' =>'aws_s3_bucket',
1772 'group_name' =>'image',
1773 'config_value' =>''),
1774 array( 'config_key' =>'aws_s3_domain',
1775 'group_name' =>'image',
1776 'config_value' =>0),
1777 array( 'config_key' =>'disallow_nudes',
1778 'group_name' =>'image',
1779 'config_value' =>0),
1780 array( 'config_key' =>'html_head',
1781 'group_name' =>'general',
1782 'config_value' =>''),
1783 array( 'config_key' =>'html_footer',
1784 'group_name' =>'general',
1785 'config_value' =>''),
1786 array( 'config_key' =>'login_to_contact',
1787 'group_name' =>'advertisement',
1788 'config_value' => 0),
1789 array( 'config_key' =>'custom_css',
1790 'group_name' =>'appearance',
1791 'config_value' => 0),
1792 array( 'config_key' =>'custom_css_version',
1793 'group_name' =>'appearance',
1794 'config_value' => 0),
1795 array( 'config_key' =>'only_admin_post',
1796 'group_name' =>'advertisement',
1797 'config_value' => 0),
1798 array( 'config_key' =>'map_active',
1799 'group_name' =>'appearance',
1800 'config_value' => 1),
1801 array( 'config_key' =>'map_jscode',
1802 'group_name' =>'appearance',
1803 'config_value' =>''),
1804 array( 'config_key' =>'map_settings',
1805 'group_name' =>'appearance',
1806 'config_value' =>''),
1807 array( 'config_key' =>'recaptcha_active',
1808 'group_name' =>'general',
1809 'config_value' =>''),
1810 array( 'config_key' =>'recaptcha_secretkey',
1811 'group_name' =>'general',
1812 'config_value' =>''),
1813 array( 'config_key' =>'recaptcha_sitekey',
1814 'group_name' =>'general',
1815 'config_value' =>''),
1816 );
1817
1818 Model_Config::config_array($configs);
1819
1820 //upgrade has_image field to use it as images count
1821 $ads = new Model_Ad();
1822 $ads = $ads->where('has_images', '>', 0)->find_all();
1823
1824 if (core::count($ads)) {
1825 foreach ($ads as $ad) {
1826 $ad->has_images = 0;//begin with 0 images
1827 $route = $ad->image_path();
1828 $folder = DOCROOT.$route;
1829 $image_keys = array();
1830
1831 if (is_dir($folder)) {
1832 //retrive ad pictures
1833 foreach (new DirectoryIterator($folder) as $file) {
1834 if (!$file->isDot()) {
1835 $key = explode('_', $file->getFilename());
1836 $key = end($key);
1837 $key = explode('.', $key);
1838 $key = (isset($key[0])) ? $key[0] : null ;
1839 if (is_numeric($key)) {
1840 if (strpos($file->getFilename(), 'thumb_') === 0) {
1841 $image_keys[] = $key;
1842 }
1843 }
1844 }
1845 }
1846
1847 //count images and reordering file names
1848 if (core::count($image_keys)) {
1849 asort($image_keys);
1850
1851 foreach ($image_keys as $image_key) {
1852 $ad->has_images++;
1853
1854 @rename($folder.$ad->seotitle.'_'.$image_key.'.jpg', $folder.$ad->seotitle.'_'.$ad->has_images.'.jpg');
1855 @rename($folder.'thumb_'.$ad->seotitle.'_'.$image_key.'.jpg', $folder.'thumb_'.$ad->seotitle.'_'.$ad->has_images.'.jpg');
1856 }
1857 }
1858 }
1859
1860 //update has_images count
1861 try {
1862 $ad->save();
1863 } catch (Exception $e) {
1864 throw HTTP_Exception::factory(500, $e->getMessage());
1865 }
1866 }
1867 }
1868
1869 //upgrade categories has_image
1870 $images_path = DOCROOT.'images/categories';
1871 if (is_dir($images_path)) {
1872 //retrive cat pictures
1873 foreach (new DirectoryIterator($images_path) as $file) {
1874 if ($file->isFile()) {
1875 $cat_name = str_replace('.png', '', $file->getFilename());
1876 $cat = new Model_Category();
1877 $cat->where('seoname', '=', $cat_name)->find();
1878 if ($cat->loaded()) {
1879 $cat->has_image = 1;
1880 $cat->save();
1881 }
1882 }
1883 }
1884 }
1885
1886
1887 //upgrade locations has_image
1888 $images_path = DOCROOT.'images/locations';
1889 if (is_dir($images_path)) {
1890 //retrive loc pictures
1891 foreach (new DirectoryIterator($images_path) as $file) {
1892 if ($file->isFile()) {
1893 $loc_name = str_replace('.png', '', $file->getFilename());
1894 $loc = new Model_Location();
1895 $loc->where('seoname', '=', $loc_name)->find();
1896 if ($loc->loaded()) {
1897 $loc->has_image = 1;
1898 $loc->save();
1899 }
1900 }
1901 }
1902 }
1903
1904 //upgrade users has_image
1905 $images_path = DOCROOT.'images/users';
1906 if (is_dir($images_path)) {
1907 //retrive user pictures
1908 foreach (new DirectoryIterator($images_path) as $file) {
1909 if ($file->isFile() and is_numeric($id_user = str_replace('.png', '', $file->getFilename()))) {
1910 $user = new Model_User($id_user);
1911 if ($user->loaded()) {
1912 $user->has_image = 1;
1913 $user->save();
1914 }
1915 }
1916 }
1917 }
1918 }
1919
1920 /**
1921 * This function will upgrade DB that didn't existed in versions prior to 2.2.1
1922 */
1923 public function action_221()
1924 {
1925 $configs = array(
1926 array( 'config_key' =>'count_visits',
1927 'group_name' =>'advertisement',
1928 'config_value' => 1),
1929 array( 'config_key' =>'disallowbots',
1930 'group_name' =>'general',
1931 'config_value' => 0),
1932
1933 );
1934
1935 Model_Config::config_array($configs);
1936 }
1937
1938 /**
1939 * This function will upgrade DB that didn't existed in versions prior to 2.2.0
1940 */
1941 public function action_220()
1942 {
1943 //updating contents replacing . for _
1944 try {
1945 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET seotitle=REPLACE(seotitle,'.','-') WHERE type='email'")->execute();
1946 } catch (exception $e) {
1947 }
1948
1949 //cleaning emails not in use
1950 try {
1951 DB::query(Database::DELETE, "DELETE FROM ".self::$db_prefix."content WHERE seotitle='user.new' AND type='email'")->execute();
1952 } catch (exception $e) {
1953 }
1954
1955 //updating contents bad names
1956 try {
1957 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET seotitle='ads-sold' WHERE seotitle='adssold' AND type='email'")->execute();
1958 } catch (exception $e) {
1959 }
1960
1961 try {
1962 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET seotitle='out-of-stock' WHERE seotitle='outofstock' AND type='email'")->execute();
1963 } catch (exception $e) {
1964 }
1965
1966 try {
1967 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET seotitle='ads-purchased' WHERE seotitle='adspurchased' AND type='email'")->execute();
1968 } catch (exception $e) {
1969 }
1970
1971 try {
1972 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET seotitle='ads-purchased' WHERE seotitle='adspurchased' AND type='email'")->execute();
1973 } catch (exception $e) {
1974 }
1975 //end updating emails
1976
1977
1978 //order transaction
1979 try {
1980 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."orders` ADD `txn_id` VARCHAR( 255 ) NULL DEFAULT NULL")->execute();
1981 } catch (exception $e) {
1982 }
1983
1984
1985 //ip_address from float to bigint
1986 try {
1987 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` CHANGE last_ip last_ip BIGINT NULL DEFAULT NULL ")->execute();
1988 } catch (exception $e) {
1989 }
1990 try {
1991 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."visits` CHANGE ip_address ip_address BIGINT NULL DEFAULT NULL ")->execute();
1992 } catch (exception $e) {
1993 }
1994 try {
1995 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` CHANGE ip_address ip_address BIGINT NULL DEFAULT NULL ")->execute();
1996 } catch (exception $e) {
1997 }
1998 try {
1999 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."posts` CHANGE ip_address ip_address BIGINT NULL DEFAULT NULL ")->execute();
2000 } catch (exception $e) {
2001 }
2002
2003 //crontab table
2004 try {
2005 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."crontab` (
2006 `id_crontab` int(10) unsigned NOT NULL AUTO_INCREMENT,
2007 `name` varchar(50) NOT NULL,
2008 `period` varchar(50) NOT NULL,
2009 `callback` varchar(140) NOT NULL,
2010 `params` varchar(255) DEFAULT NULL,
2011 `description` varchar(255) DEFAULT NULL,
2012 `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2013 `date_started` datetime DEFAULT NULL,
2014 `date_finished` datetime DEFAULT NULL,
2015 `date_next` datetime DEFAULT NULL,
2016 `times_executed` bigint DEFAULT '0',
2017 `output` varchar(50) DEFAULT NULL,
2018 `running` tinyint(1) NOT NULL DEFAULT '0',
2019 `active` tinyint(1) NOT NULL DEFAULT '1',
2020 PRIMARY KEY (`id_crontab`),
2021 UNIQUE KEY `".self::$db_prefix."crontab_UK_name` (`name`)
2022 ) ENGINE=MyISAM;")->execute();
2023 } catch (exception $e) {
2024 }
2025
2026 //crontabs
2027 try {
2028 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES
2029 ('Sitemap', '00 3 * * *', 'Sitemap::generate', NULL, 'Regenerates the sitemap everyday at 3am',1),
2030 ('Clean Cache', '00 5 * * *', 'Core::delete_cache', NULL, 'Once day force to flush all the cache.', 1),
2031 ('Optimize DB', '00 4 1 * *', 'Core::optimize_db', NULL, 'once a month we optimize the DB', 1),
2032 ('Unpaid Orders', '00 7 * * *', 'Cron_Ad::unpaid', NULL, 'Notify by email unpaid orders 2 days after was created', 1),
2033 ('Expired Featured Ad', '00 8 * * *', 'Cron_Ad::expired_featured', NULL, 'Notify by email of expired featured ad', 1),
2034 ('Expired Ad', '00 9 * * *', 'Cron_Ad::expired', NULL, 'Notify by email of expired ad', 1);")->execute();
2035 } catch (exception $e) {
2036 }
2037
2038 //delete old sitemap config
2039 try {
2040 DB::query(Database::DELETE, "DELETE FROM ".self::$db_prefix."config WHERE (config_key='expires' OR config_key='on_post') AND group_name='sitemap'")->execute();
2041 } catch (exception $e) {
2042 }
2043
2044 //categories description to HTML
2045 try {
2046 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."categories` CHANGE `description` `description` TEXT NULL DEFAULT NULL;")->execute();
2047 } catch (exception $e) {
2048 }
2049
2050 $categories = new Model_Category();
2051 $categories = $categories->find_all();
2052 foreach ($categories as $category) {
2053 $category->description = Text::bb2html($category->description, true, false);
2054 try {
2055 $category->save();
2056 } catch (Exception $e) {
2057 }
2058 }
2059
2060 //locations description to HTML
2061 try {
2062 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."locations` CHANGE `description` `description` TEXT NULL DEFAULT NULL;")->execute();
2063 } catch (exception $e) {
2064 }
2065
2066 $locations = new Model_Location();
2067 $locations = $locations->find_all();
2068 foreach ($locations as $location) {
2069 $location->description = Text::bb2html($location->description, true, false);
2070 try {
2071 $location->save();
2072 } catch (Exception $e) {
2073 }
2074 }
2075
2076 //content description to HTML
2077
2078 $contents = new Model_Content();
2079 $contents = $contents->find_all();
2080 foreach ($contents as $content) {
2081 $content->description = Text::bb2html($content->description, true, false);
2082 try {
2083 $content->save();
2084 } catch (Exception $e) {
2085 }
2086 }
2087
2088 //blog description to HTML
2089
2090 $posts = new Model_Post();
2091 $posts = $posts->where('id_forum', 'IS', null)->find_all();
2092 foreach ($posts as $post) {
2093 $post->description = Text::bb2html($post->description, true, false);
2094 try {
2095 $post->save();
2096 } catch (Exception $e) {
2097 }
2098 }
2099
2100 //Reviews
2101 try {
2102 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `rate` FLOAT( 4, 2 ) NULL DEFAULT NULL ;")->execute();
2103 } catch (exception $e) {
2104 }
2105
2106 try {
2107 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` ADD `rate` FLOAT( 4, 2 ) NULL DEFAULT NULL ;")->execute();
2108 } catch (exception $e) {
2109 }
2110
2111 try {
2112 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS ".self::$db_prefix."reviews (
2113 id_review int(10) unsigned NOT NULL AUTO_INCREMENT,
2114 id_user int(10) unsigned NOT NULL,
2115 id_ad int(10) unsigned NOT NULL,
2116 rate int(2) unsigned NOT NULL DEFAULT '0',
2117 description varchar(1000) NOT NULL,
2118 created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2119 ip_address float DEFAULT NULL,
2120 status tinyint(1) NOT NULL DEFAULT '0',
2121 PRIMARY KEY (id_review) USING BTREE,
2122 KEY ".self::$db_prefix."reviews_IK_id_user (id_user),
2123 KEY ".self::$db_prefix."reviews_IK_id_ad (id_ad)
2124 ) ENGINE=MyISAM;")->execute();
2125 } catch (Exception $e) {
2126 }
2127
2128 //User description About
2129 try {
2130 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `description` TEXT NULL DEFAUlT NULL AFTER `password` ")->execute();
2131 } catch (exception $e) {
2132 }
2133
2134 //Favorites table
2135 try {
2136 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS ".self::$db_prefix."favorites (
2137 id_favorite int(10) unsigned NOT NULL AUTO_INCREMENT,
2138 id_user int(10) unsigned NOT NULL,
2139 id_ad int(10) unsigned NOT NULL,
2140 created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2141 PRIMARY KEY (id_favorite) USING BTREE,
2142 KEY ".self::$db_prefix."favorites_IK_id_user_AND_id_ad (id_user,id_ad)
2143 ) ENGINE=MyISAM;")->execute();
2144 } catch (Exception $e) {
2145 }
2146
2147 //new mails
2148 $contents = array(array('order'=>0,
2149 'title'=>'Receipt for [ORDER.DESC] #[ORDER.ID]',
2150 'seotitle'=>'new-order',
2151 'description'=>"Hello [USER.NAME],Thanks for buying [ORDER.DESC].\n\nPlease complete the payment here [URL.CHECKOUT]",
2152 'from_email'=>core::config('email.notify_email'),
2153 'type'=>'email',
2154 'status'=>'1'),
2155 array('order'=>0,
2156 'title'=>'Your ad [AD.NAME] has expired',
2157 'seotitle'=>'ad-expired',
2158 'description'=>"Hello [USER.NAME],Your ad [AD.NAME] has expired \n\nPlease check your ad here [URL.EDITAD]",
2159 'from_email'=>core::config('email.notify_email'),
2160 'type'=>'email',
2161 'status'=>'1'),
2162 array('order'=>'0',
2163 'title'=>'New review for [AD.TITLE] [RATE]',
2164 'seotitle'=>'ad-review',
2165 'description'=>'[URL.QL]\n\n[RATE]\n\n[DESCRIPTION]',
2166 'from_email'=>core::config('email.notify_email'),
2167 'type'=>'email',
2168 'status'=>'1'),
2169 );
2170
2171 Model_Content::content_array($contents);
2172
2173 //new configs...
2174 $configs = array(
2175 array('config_key' =>'bitpay_apikey',
2176 'group_name' =>'payment',
2177 'config_value' =>''),
2178 array('config_key' =>'paymill_private',
2179 'group_name' =>'payment',
2180 'config_value' =>''),
2181 array('config_key' =>'paymill_public',
2182 'group_name' =>'payment',
2183 'config_value' =>''),
2184 array('config_key' =>'stripe_public',
2185 'group_name' =>'payment',
2186 'config_value' =>''),
2187 array('config_key' =>'stripe_private',
2188 'group_name' =>'payment',
2189 'config_value' =>''),
2190 array('config_key' =>'stripe_address',
2191 'group_name' =>'payment',
2192 'config_value' =>'0'),
2193 array('config_key' =>'alternative',
2194 'group_name' =>'payment',
2195 'config_value' =>''),
2196 array('config_key' =>'authorize_sandbox',
2197 'group_name' =>'payment',
2198 'config_value' =>'0'),
2199 array('config_key' =>'authorize_login',
2200 'group_name' =>'payment',
2201 'config_value' =>''),
2202 array('config_key' =>'authorize_key',
2203 'group_name' =>'payment',
2204 'config_value' =>''),
2205 array('config_key' =>'elastic_active',
2206 'group_name' =>'email',
2207 'config_value' =>0),
2208 array('config_key' =>'elastic_username',
2209 'group_name' =>'email',
2210 'config_value' =>''),
2211 array('config_key' =>'elastic_password',
2212 'group_name' =>'email',
2213 'config_value' =>''),
2214 array('config_key' =>'reviews',
2215 'group_name' =>'advertisement',
2216 'config_value' =>'0'),
2217 array('config_key' =>'reviews_paid',
2218 'group_name' =>'advertisement',
2219 'config_value' =>'0'),
2220 );
2221
2222 Model_Config::config_array($configs);
2223
2224 //delete old files from 323, no need they need to update manually
2225 // File::delete(APPPATH.'ko323');
2226 // File::delete(APPPATH.'classes/image/');
2227
2228 // //delete modules since now they are part of module common
2229 // File::delete(MODPATH.'pagination');
2230 // File::delete(MODPATH.'breadcrumbs');
2231 // File::delete(MODPATH.'formmanager');
2232 // File::delete(MODPATH.'mysqli');
2233
2234 //assign new group_name to configs
2235 try {
2236 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."config SET group_name='advertisement' WHERE config_key = 'advertisements_per_page' OR config_key = 'feed_elements' OR config_key = 'map_elements' OR config_key = 'sort_by'")->execute();
2237 } catch (exception $e) {
2238 }
2239 DB::query(Database::UPDATE, "UPDATE ".self::$db_prefix."content SET seotitle=REPLACE(seotitle,'.','-') WHERE type='email'")->execute();
2240 }
2241
2242 /**
2243 * This function will upgrade DB that didn't existed in versions prior to 2.1.8
2244 */
2245 public function action_218()
2246 {
2247 try {
2248 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."config DROP INDEX ".self::$db_prefix."config_IK_group_name_AND_config_key")->execute();
2249 } catch (exception $e) {
2250 }
2251
2252 try {
2253 DB::query(Database::UPDATE, "ALTER TABLE ".self::$db_prefix."config ADD PRIMARY KEY (config_key);")->execute();
2254 } catch (exception $e) {
2255 }
2256
2257 try {
2258 DB::query(Database::UPDATE, "CREATE UNIQUE INDEX ".self::$db_prefix."config_UK_group_name_AND_config_key ON ".self::$db_prefix."config(`group_name` ,`config_key`)")->execute();
2259 } catch (exception $e) {
2260 }
2261
2262 $configs = array(
2263 array('config_key' =>'login_to_post',
2264 'group_name' =>'advertisement',
2265 'config_value' =>'0'),
2266 );
2267
2268 // returns TRUE if some config is saved
2269 $return_conf = Model_Config::config_array($configs);
2270
2271 //delete old files from 322
2272 File::delete(APPPATH.'ko322');
2273 File::delete(MODPATH.'auth');
2274 File::delete(MODPATH.'cache');
2275 File::delete(MODPATH.'database');
2276 File::delete(MODPATH.'image');
2277 File::delete(MODPATH.'orm');
2278 File::delete(MODPATH.'unittest');
2279 }
2280
2281 /**
2282 * This function will upgrade DB that didn't existed in versions prior to 2.1.7
2283 */
2284 public function action_217()
2285 {
2286 try {
2287 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."posts` ADD `id_post_parent` INT NULL DEFAULT NULL AFTER `id_user`")->execute();
2288 } catch (exception $e) {
2289 }
2290 try {
2291 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."posts` ADD `ip_address` FLOAT NULL DEFAULT NULL AFTER `created`")->execute();
2292 } catch (exception $e) {
2293 }
2294 try {
2295 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."posts` ADD `id_forum` INT NULL DEFAULT NULL AFTER `id_post_parent`")->execute();
2296 } catch (exception $e) {
2297 }
2298 try {
2299 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."posts` ENGINE = MYISAM ")->execute();
2300 } catch (exception $e) {
2301 }
2302
2303
2304 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."forums` (
2305 `id_forum` int(10) unsigned NOT NULL AUTO_INCREMENT,
2306 `name` varchar(145) NOT NULL,
2307 `order` int(2) unsigned NOT NULL DEFAULT '0',
2308 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2309 `id_forum_parent` int(10) unsigned NOT NULL DEFAULT '0',
2310 `parent_deep` int(2) unsigned NOT NULL DEFAULT '0',
2311 `seoname` varchar(145) NOT NULL,
2312 `description` varchar(255) NULL,
2313 PRIMARY KEY (`id_forum`) USING BTREE,
2314 UNIQUE KEY `".self::$db_prefix."forums_IK_seo_name` (`seoname`)
2315 ) ENGINE=MyISAM")->execute();
2316
2317 // build array with new (missing) configs
2318
2319 //set sitemap to 0
2320 Model_Config::set_value('sitemap', 'on_post', 0);
2321
2322 $configs = array(
2323 array('config_key' =>'forums',
2324 'group_name' =>'general',
2325 'config_value' =>'0'),
2326 array('config_key' =>'ocacu',
2327 'group_name' =>'general',
2328 'config_value' =>'0'),
2329 );
2330
2331 // returns TRUE if some config is saved
2332 $return_conf = Model_Config::config_array($configs);
2333 }
2334
2335 /**
2336 * This function will upgrade DB that didn't existed in versions prior to 2.1.5
2337 */
2338 public function action_215()
2339 {
2340 // build array with new (missing) configs
2341 $configs = array(array('config_key' =>'qr_code',
2342 'group_name' =>'advertisement',
2343 'config_value' =>'0'),
2344 array('config_key' =>'black_list',
2345 'group_name' =>'general',
2346 'config_value' =>'1'),
2347 array('config_key' =>'stock',
2348 'group_name' =>'payment',
2349 'config_value' =>'0'),
2350 array('config_key' =>'fbcomments',
2351 'group_name' =>'advertisement',
2352 'config_value' =>''),
2353 );
2354 $contents = array(array('order'=>'0',
2355 'title'=>'Advertisement `[AD.TITLE]` is sold on [SITE.NAME]!',
2356 'seotitle'=>'ads-sold',
2357 'description'=>"Order ID: [ORDER.ID]\n\nProduct ID: [PRODUCT.ID]\n\nPlease check your bank account for the incoming payment.\n\nClick here to visit [URL.AD]", // @FIXME i18n ?
2358 'from_email'=>core::config('email.notify_email'),
2359 'type'=>'email',
2360 'status'=>'1'),
2361 array('order'=>'0',
2362 'title'=>'Advertisement `[AD.TITLE]` is purchased on [SITE.NAME]!',
2363 'seotitle'=>'ads-purchased',
2364 'description'=>"Order ID: [ORDER.ID]\n\nProduct ID: [PRODUCT.ID]\n\nFor any inconvenience please contact administrator of [SITE.NAME], with a details provided above.\n\nClick here to visit [URL.AD]", // @FIXME i18n ?
2365 'from_email'=>core::config('email.notify_email'),
2366 'type'=>'email',
2367 'status'=>'1'),
2368 array('order'=>'0',
2369 'title'=>'Advertisement `[AD.TITLE]` is out of stock on [SITE.NAME]!',
2370 'seotitle'=>'out-of-stock',
2371 'description'=>"Hello [USER.NAME],\n\nWhile your ad is out of stock, it is unavailable for others to see. If you wish to increase stock and activate, please follow this link [URL.EDIT].\n\nRegards!", // @FIXME i18n ?
2372 'from_email'=>core::config('email.notify_email'),
2373 'type'=>'email',
2374 'status'=>'1'),);
2375
2376 // returns TRUE if some config is saved
2377 $return_conf = Model_Config::config_array($configs);
2378 $return_cont = Model_Content::content_array($contents);
2379
2380
2381 try {
2382 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `subscriber` tinyint(1) NOT NULL DEFAULT '1'")->execute();
2383 } catch (exception $e) {
2384 }
2385 try {
2386 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."ads` ADD `stock` int(10) unsigned DEFAULT NULL")->execute();
2387 } catch (exception $e) {
2388 }
2389 try {
2390 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."roles` (`id_role`, `name`, `description`) VALUES (7, 'moderator', 'Limited access')")->execute();
2391 } catch (exception $e) {
2392 }
2393 try {
2394 DB::query(Database::UPDATE, "INSERT INTO `".self::$db_prefix."access` (`id_access`, `id_role`, `access`) VALUES
2395 (17, 7, 'location.*'),(16, 7, 'profile.*'),(15, 7, 'content.*'),(14, 7, 'stats.user'),
2396 (13, 7, 'blog.*'),(12, 7, 'translations.*'),(11, 7, 'ad.*'),
2397 (10, 7, 'widgets.*'),(9, 7, 'menu.*'),(8, 7, 'category.*')")->execute();
2398 } catch (exception $e) {
2399 }
2400 }
2401
2402 /**
2403 * This function will upgrade DB that didn't existed in versions prior to 2.1.3
2404 */
2405 public function action_214()
2406 {
2407 // build array with new (missing) configs
2408 $configs = array(array('config_key' =>'sort_by',
2409 'group_name' =>'general',
2410 'config_value' =>'published-desc'),
2411 array('config_key' =>'map_pub_new',
2412 'group_name' =>'advertisement',
2413 'config_value' =>'0'),
2414 );
2415
2416 // returns TRUE if some config is saved
2417 $return_conf = Model_Config::config_array($configs);
2418 }
2419
2420 /**
2421 * This function will upgrade DB that didn't existed in versions prior to 2.1
2422 */
2423 public function action_211()
2424 {
2425 // build array with new (missing) configs
2426 $configs = array(array('config_key' =>'related',
2427 'group_name' =>'advertisement',
2428 'config_value' =>'5'),
2429 array('config_key' =>'faq',
2430 'group_name' =>'general',
2431 'config_value' =>'0'),
2432 array('config_key' =>'faq_disqus',
2433 'group_name' =>'general',
2434 'config_value' =>''),
2435 );
2436
2437 // returns TRUE if some config is saved
2438 $return_conf = Model_Config::config_array($configs);
2439 }
2440
2441 /**
2442 * This function will upgrade DB that didn't existed in versions prior to 2.0.7
2443 * changes added: config for advanced search by description
2444 */
2445 public function action_210()
2446 {
2447 try {
2448 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."users` ADD `hybridauth_provider_name` VARCHAR( 40 ) NULL DEFAULT NULL ,ADD `hybridauth_provider_uid` VARCHAR( 191 ) NULL DEFAULT NULL")->execute();
2449 } catch (exception $e) {
2450 }
2451 try {
2452 DB::query(Database::UPDATE, "CREATE UNIQUE INDEX ".self::$db_prefix."users_UK_provider_AND_uid on ".self::$db_prefix."users (hybridauth_provider_name, hybridauth_provider_uid)")->execute();
2453 } catch (exception $e) {
2454 }
2455
2456 try {
2457 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."posts` (
2458 `id_post` int(10) unsigned NOT NULL AUTO_INCREMENT,
2459 `id_user` int(10) unsigned NOT NULL,
2460 `title` varchar(245) NOT NULL,
2461 `seotitle` varchar(191) NOT NULL,
2462 `description` text NOT NULL,
2463 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
2464 `status` tinyint(1) NOT NULL DEFAULT '0',
2465 PRIMARY KEY (`id_post`) USING BTREE,
2466 UNIQUE KEY `".self::$db_prefix."posts_UK_seotitle` (`seotitle`)
2467 ) ENGINE=InnoDB DEFAULT CHARSET=".self::$db_charset.";")->execute();
2468 } catch (exception $e) {
2469 }
2470
2471
2472 // build array with new (missing) configs
2473 $configs = array(array('config_key' =>'search_by_description',
2474 'group_name' =>'general',
2475 'config_value' => 0),
2476 array('config_key' =>'blog',
2477 'group_name' =>'general',
2478 'config_value' => 0),
2479 array('config_key' =>'minify',
2480 'group_name' =>'general',
2481 'config_value' => 0),
2482 array('config_key' =>'parent_category',
2483 'group_name' =>'advertisement',
2484 'config_value' => 1),
2485 array('config_key' =>'blog_disqus',
2486 'group_name' =>'general',
2487 'config_value' => ''),
2488 array('config_key' =>'config',
2489 'group_name' =>'social',
2490 'config_value' =>'{"debug_mode":"0","providers":{
2491 "OpenID":{"enabled":"1"},
2492 "Yahoo":{"enabled":"0","keys":{"id":"","secret":""}},
2493 "AOL":{"enabled":"1"}
2494 ,"Google":{"enabled":"0","keys":{"id":"","secret":""}},
2495 "Facebook":{"enabled":"0","keys":{"id":"","secret":""}},
2496 "Twitter":{"enabled":"0","keys":{"key":"","secret":""}},
2497 "Live":{"enabled":"0","keys":{"id":"","secret":""}},
2498 "MySpace":{"enabled":"0","keys":{"key":"","secret":""}},
2499 "LinkedIn":{"enabled":"0","keys":{"key":"","secret":""}},
2500 "Foursquare":{"enabled":"0","keys":{"id":"","secret":""}}},
2501 "base_url":"",
2502 "debug_file":""}'));
2503
2504 // returns TRUE if some config is saved
2505 $return_conf = Model_Config::config_array($configs);
2506 }
2507
2508 /**
2509 * This function will upgrade DB that didn't existed in versions prior to 2.0.6
2510 * changes added: config for custom field
2511 */
2512 public function action_207()
2513 {
2514 // build array with new (missing) configs
2515 $configs = array(array('config_key' =>'fields',
2516 'group_name' =>'advertisement',
2517 'config_value' =>''),
2518 array('config_key' =>'alert_terms',
2519 'group_name' =>'general',
2520 'config_value' =>''),
2521 );
2522
2523 // returns TRUE if some config is saved
2524 $return_conf = Model_Config::config_array($configs);
2525 }
2526
2527 /**
2528 * This function will upgrade DB that didn't existed in versions prior to 2.0.5
2529 * changes added: config for landing page, etc..
2530 */
2531 public function action_206()
2532 {
2533 // build array with new (missing) configs
2534 $configs = array(array('config_key' =>'landing_page',
2535 'group_name' =>'general',
2536 'config_value' =>'{"controller":"home","action":"index"}'),
2537 array('config_key' =>'banned_words',
2538 'group_name' =>'advertisement',
2539 'config_value' =>''),
2540 array('config_key' =>'banned_words_replacement',
2541 'group_name' =>'advertisement',
2542 'config_value' =>''),
2543 array('config_key' =>'akismet_key',
2544 'group_name' =>'general',
2545 'config_value' =>''));
2546
2547 // returns TRUE if some config is saved
2548 $return_conf = Model_Config::config_array($configs);
2549 }
2550
2551 /**
2552 * This function will upgrade DB that didn't existed in versions prior to 2.0.5
2553 * changes added: subscription widget, new email content, map zoom, paypal seller etc..
2554 */
2555 public function action_205()
2556 {
2557 // build array with new (missing) configs
2558 $configs = array(array('config_key' =>'paypal_seller',
2559 'group_name' =>'payment',
2560 'config_value' =>'0'),
2561 array('config_key' =>'map_zoom',
2562 'group_name' =>'advertisement',
2563 'config_value' =>'16'),
2564 array('config_key' =>'center_lon',
2565 'group_name' =>'advertisement',
2566 'config_value' =>'3'),
2567 array('config_key' =>'center_lat',
2568 'group_name' =>'advertisement',
2569 'config_value' =>'40'),
2570 array('config_key' =>'new_ad_notify',
2571 'group_name' =>'email',
2572 'config_value' =>'0'));
2573
2574 $contents = array(array('order'=>'0',
2575 'title'=>'Advertisement `[AD.TITLE]` is created on [SITE.NAME]!',
2576 'seotitle'=>'ads_subscribers',
2577 'description'=>"Hello,\n\nYou may be interested in this one [AD.TITLE]!\n\nYou can visit this link to see advertisement [URL.AD]",
2578 'from_email'=>core::config('email.notify_email'),
2579 'type'=>'email',
2580 'status'=>'1'),
2581 array('order'=>'0',
2582 'title'=>'Advertisement `[AD.TITLE]` is created on [SITE.NAME]!',
2583 'seotitle'=>'ads-to-admin',
2584 'description'=>"Click here to visit [URL.AD]",
2585 'from_email'=>core::config('email.notify_email'),
2586 'type'=>'email',
2587 'status'=>'1'));
2588
2589 // returns TRUE if some config is saved
2590 $return_conf = Model_Config::config_array($configs);
2591 $return_cont = Model_Content::content_array($contents);
2592
2593
2594
2595 try {
2596 DB::query(Database::UPDATE, "CREATE TABLE IF NOT EXISTS `".self::$db_prefix."subscribers` (
2597 `id_subscribe` int(10) unsigned NOT NULL AUTO_INCREMENT,
2598 `id_user` int(10) unsigned NOT NULL,
2599 `id_category` int(10) unsigned NOT NULL DEFAULT '0',
2600 `id_location` int(10) unsigned NOT NULL DEFAULT '0',
2601 `min_price` decimal(14,3) NOT NULL DEFAULT '0',
2602 `max_price` decimal(14,3) NOT NULL DEFAULT '0',
2603 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2604 PRIMARY KEY (`id_subscribe`)
2605 ) ENGINE=MyISAM DEFAULT CHARSET=".self::$db_charset.";")->execute();
2606 } catch (exception $e) {
2607 }
2608
2609 // remove INDEX from content table
2610 try {
2611 DB::query(Database::UPDATE, "ALTER TABLE `".self::$db_prefix."content` DROP INDEX `".self::$db_prefix."content_UK_seotitle`")->execute();
2612 } catch (exception $e) {
2613 }
2614 }
2615
2616
2617 /**
2618 * This function will upgrade configs that didn't existed in versions prior to 2.0.3
2619 */
2620 public function action_203()
2621 {
2622 // build array with new (missing) configs
2623 $configs = array(array('config_key' =>'watermark',
2624 'group_name' =>'image',
2625 'config_value' =>'0'),
2626 array('config_key' =>'watermark_path',
2627 'group_name' =>'image',
2628 'config_value' =>''),
2629 array('config_key' =>'watermark_position',
2630 'group_name' =>'image',
2631 'config_value' =>'0'),
2632 array('config_key' =>'ads_in_home',
2633 'group_name' =>'advertisement',
2634 'config_value' =>'0'));
2635
2636 $contents = array(array('order'=>'0',
2637 'title'=>'Hello [USER.NAME]!',
2638 'seotitle'=>'user-profile-contact',
2639 'description'=>"User [EMAIL.SENDER] [EMAIL.FROM], have a message for you: \n\n [EMAIL.SUBJECT] \n\n[EMAIL.BODY]. \n\n Regards!",
2640 'from_email'=>core::config('email.notify_email'),
2641 'type'=>'email',
2642 'status'=>'1'));
2643
2644 // returns TRUE if some config is saved
2645 $return_conf = Model_Config::config_array($configs);
2646 $return_cont = Model_Content::content_array($contents);
2647 }
2648
2649
2650
2651 public static $db_prefix = null;
2652 public static $db_charset = null;
2653
2654 //list of files to ignore the copy, TODO ignore languages folder?
2655 public static $update_ignore_list = array('robots.txt',
2656 'oc/config/auth.php',
2657 'oc/config/database.php',
2658 '.htaccess',
2659 'sitemap.xml.gz',
2660 'sitemap.xml',
2661 'install/',
2662 );
2663
2664
2665 public function __construct($request, $response)
2666 {
2667 ignore_user_abort(true);
2668 parent::__construct($request, $response);
2669
2670 self::$db_prefix = Database::instance('default')->table_prefix();
2671 self::$db_charset = Core::config('database.default.charset');
2672 }
2673
2674 public function action_index()
2675 {
2676
2677 //force update check reload
2678 if (Core::get('reload')==1) {
2679 Core::get_updates(true);
2680 Alert::set(Alert::INFO, __('Checked for new versions.'));
2681 }
2682
2683 $versions = core::config('versions');
2684
2685 if (Core::get('json')==1) {
2686 $this->auto_render = false;
2687 $this->template = View::factory('js');
2688 $this->template->content = json_encode($versions);
2689 } else {
2690 $this->template->title = __('Updates');
2691 Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
2692
2693 //version numbers in a key value
2694 $version_nums = array();
2695 foreach ($versions as $version=>$values) {
2696 $version_nums[] = $version;
2697 }
2698
2699 $latest_version = current($version_nums);
2700 $latest_version_update = next($version_nums);
2701
2702
2703 //pass to view from local versions.php
2704 $this->template->content = View::factory('oc-panel/pages/update/index', array('versions' =>$versions,
2705 'latest_version' =>$latest_version));
2706 }
2707 }
2708
2709 /**
2710 * STEP 0
2711 * Confirm you want to update!
2712 */
2713 public function action_confirm()
2714 {
2715 //force update check reload so we are sure he has latest version
2716 Core::get_updates(true);
2717
2718 $versions = core::config('versions');
2719
2720
2721 $this->template->title = __('Updates');
2722 Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
2723 $this->template->scripts['footer'][] = 'js/oc-panel/update.js';
2724
2725 //version numbers in a key value
2726 $version_nums = array();
2727 foreach ($versions as $version=>$values) {
2728 $version_nums[] = $version;
2729 }
2730
2731 //latest version available
2732 $latest_version = current($version_nums);
2733
2734 //info from the latest version available
2735 $version = $versions[$latest_version];
2736
2737 //this is the version we allow to update from. Only the one before latest
2738 $latest_version_update = (int) str_replace('.', '', next($version_nums));
2739
2740 //current installation version
2741 $current_version = (int) str_replace('.', '', core::VERSION);
2742
2743 $can_update = false;
2744
2745 if ($current_version == $latest_version_update) {
2746 $can_update = true;
2747 }
2748
2749 //pass to view from local versions.php
2750 $this->template->content = View::factory('oc-panel/pages/update/confirm', array('latest_version'=>$latest_version,
2751 'version' =>$version,
2752 'can_update'=>$can_update));
2753 }
2754
2755 /**
2756 * STEP 1
2757 * Downloads and extracts latest version
2758 */
2759 public function action_latest()
2760 {
2761 //save in a session the current version so we can selective update the DB later
2762 Session::instance()->set('update_from_version', Core::VERSION);
2763
2764 $versions = (array) core::config('versions'); //loads OC software version array
2765 $last_version = key($versions); //get latest version
2766 $download_url = $versions[$last_version]['download']; //get latest download link
2767 $update_src_dir = DOCROOT.'update'; // update dir
2768 $file_name = $update_src_dir.'/'.$last_version.'.zip'; //full file name
2769
2770 //check if exists already the download, if does delete
2771 if (file_exists($file_name))
2772 {
2773 unlink($file_name);
2774 }
2775
2776 //create update dir if doesnt exists
2777 if (!is_dir($update_src_dir))
2778 {
2779 mkdir($update_src_dir, 0775);
2780 }
2781
2782 //get redirected url from download if any
2783 if ($download_headers = get_headers($download_url, 1) AND
2784 isset($download_headers['Location']))
2785 {
2786 $download_url = is_array($download_headers['Location'])
2787 ? end($download_headers['Location'])
2788 : $download_headers['Location'];
2789 }
2790
2791 //verify we could get the zip file
2792 $file_content = core::curl_get_contents($download_url);
2793
2794 if ($file_content == FALSE)
2795 {
2796 Alert::set(Alert::ALERT, __('We had a problem downloading latest version, try later please.'));
2797 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'index')));
2798 }
2799
2800 //Write the file
2801 file_put_contents($file_name, $file_content);
2802
2803 //unpack zip
2804 $zip = new ZipArchive;
2805
2806 // open zip file, and extract to dir
2807 if ($zip->open($file_name))
2808 {
2809 $zip->extractTo($update_src_dir);
2810 $zip->close();
2811 }
2812 else
2813 {
2814 Alert::set(Alert::ALERT, $file_name.' '.__('Zip file failed to extract, please try again.'));
2815 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'index')));
2816 }
2817
2818 //delete downloaded file
2819 unlink($file_name);
2820
2821 //move files in different request so more time
2822 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'files')));
2823 }
2824
2825 /**
2826 * STEP 2
2827 * this controller moves the extracted files
2828 */
2829 public function action_files()
2830 {
2831 $update_src_dir = DOCROOT.'update'; // update dir
2832
2833 //getting the directory where the zip was uncompressed
2834 foreach (new DirectoryIterator($update_src_dir) as $file) {
2835 if ($file->isDir() and !$file->isDot()) {
2836 $folder_udpate = $file->getFilename();
2837 break;
2838 }
2839 }
2840
2841 $from = $update_src_dir.'/'.$folder_udpate;
2842
2843 //can we access the folder?
2844 if (is_dir($from)) {
2845 //so we just simply delete the ignored files ;)
2846 foreach (self::$update_ignore_list as $file) {
2847 File::delete($from.'/'.$file);
2848 }
2849
2850 //activate maintenance mode since we are moving files...
2851 Model_Config::set_value('general', 'maintenance', 1);
2852
2853 //copy from update to docroot only if files different size
2854 File::copy($from, DOCROOT, 1);
2855 } else {
2856 Alert::set(Alert::ALERT, $from.' '.sprintf(__('Update folder `%s` not found.'), $from));
2857 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'index')));
2858 }
2859
2860 //delete update files when all finished
2861 File::delete($update_src_dir);
2862
2863 //clean cache
2864 Core::delete_cache();
2865
2866 //deactivate maintenance mode
2867 Model_Config::set_value('general', 'maintenance', 0);
2868
2869 //update the DB in different request
2870 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'database')));
2871 }
2872
2873
2874 /**
2875 * STEP 3
2876 * Updates the DB using the functions action_XX
2877 * they are actions, just in case you want to launch the update of a specific release like /oc-panel/update/218 for example
2878 */
2879 public function action_database()
2880 {
2881 //activate maintenance mode
2882 Model_Config::set_value('general', 'maintenance', 1);
2883
2884 //getting the version from where we are upgrading
2885 $from_version = Session::instance()->get('update_from_version', Core::get('from_version', Core::VERSION));
2886 $from_version = str_replace('.', '', $from_version);//getting the integer
2887 //$from_version = substr($from_version,0,3);//we allow only 3 digits updates, if update has more than 3 its a minor release no DB changes?
2888 $from_version = (int) $from_version;
2889
2890 //we get all the DB updates available
2891 $db_updates = $this->get_db_action_methods();
2892
2893 foreach ($db_updates as $version) {
2894 //we only execute those that are newer or same
2895 if ($version >= $from_version) {
2896 call_user_func(array($this, (string)'action_'.$version));
2897 Alert::set(Alert::INFO, __('Updated to ').$version);
2898 }
2899 }
2900
2901 //deactivate maintenance mode
2902 Model_Config::set_value('general', 'maintenance', 0);
2903
2904 Alert::set(Alert::SUCCESS, __('Software DB Updated to latest version!'));
2905
2906 //clean cache
2907 Core::delete_cache();
2908
2909 //TODO maybe a setting that forces the update of the themes?
2910 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'themes')));
2911 }
2912
2913 /**
2914 * STEP 4 and last
2915 * updates all themes to latest version from API license
2916 * @return void
2917 */
2918 public function action_themes()
2919 {
2920 //only if theres work to do ;)
2921 if (Core::config('license.number')!='') {
2922 //activate maintenance mode
2923 Model_Config::set_value('general', 'maintenance', 1);
2924
2925 //store the theme he is using now
2926 $current_theme = Core::config('appearance.theme');
2927
2928 //activate default theme
2929 Model_Config::set_value('appearance', 'theme', 'default');
2930
2931 Core::download(Core::config('license.number'));
2932
2933 //activate original theme
2934 Model_Config::set_value('appearance', 'theme', $current_theme);
2935
2936 //deactivate maintenance mode
2937 Model_Config::set_value('general', 'maintenance', 0);
2938
2939 //clean cache
2940 Core::delete_cache();
2941 }
2942
2943 //finished the entire update process
2944 $this->redirect(Route::url('oc-panel', array('controller'=>'update', 'action'=>'index')));
2945 }
2946
2947 /**
2948 * we get all the DB updates available
2949 * @return array
2950 */
2951 private function get_db_action_methods()
2952 {
2953 $updates = array();
2954
2955 $class = new ReflectionClass($this);
2956 $methods = $class->getMethods();
2957 foreach ($methods as $obj => $val) {
2958 //only if they are actions and numeric ;)
2959 if (is_numeric($version = str_replace('action_', '', $val->name))) {
2960 $updates[] = $version;
2961 }
2962 }
2963
2964 //from less to more, so they are executed in order for sure
2965 sort($updates);
2966
2967 return $updates;
2968 }
2969}