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