-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.php
97 lines (79 loc) · 3.15 KB
/
convert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<pre>
<?php
/*
* Старая база - в новую базу
*/
ini_set('memory_limit', '1024M');
ini_set('display_errors', 1);
error_reporting(E_ALL);
set_time_limit(0);
include 'config.php';
if (file_exists('localconfig.php'))
require_once 'localconfig.php';
else
$local_config = array();
Config::init($local_config);
include 'include.php';
// users
Database::query('TRUNCATE `users`');
$query = 'SELECT * FROM `fashist`.`users`';
$users = Database::sql2array($query);
//`uid`, `sex`, `name`, `nick`, `email`, `role`, `pass`, `hash`, `avatar`, `comments`, `last_enter`, `last_action`, `reg_date`, `icq`, `phone`, `url`, `hard_email`, `ya_email_id`
//`id`, `sex`, `name`, `nick`, `email`, `role`, `pass`, `hash`, `avatar`, `comments`, `last_enter`, `last_action`, `reg_date`, `icq`, `phone`, `url`, `hard_email`, `ya_email_id`, `lastSave`, `lastLogin`, `bday`, `city_id`
foreach ($users as $user) {
$user['role'] = $user['role'] == 5 ? 50 : 30;
$user['id'] = $user['uid'];
if (!$user['nick'])
$user['nick'] = substr($user['email'], 1, strpos($user['email'], '@'));
$newNick2 = $user['nick'].'_';
unset($user['uid']);
$sqlp = array();
foreach ($user as $f => $v) {
$sqlp[] = '`' . $f . '`=' . Database::escape($v);
}
$query = 'INSERT INTO `users` SET
' . implode(',', $sqlp) . ' ON DUPLICATE KEY UPDATE `nick`='.Database::escape($newNick2);
Database::query($query);
}
// news
Database::query('TRUNCATE `news`');
$query = 'SELECT * FROM `fashist`.`module_news` WHERE `type`=0';
$news = Database::sql2array($query, 'id');
foreach ($news as $id => $newsitem) {
$object = News::getInstance()->getById($id);
/* @var $object Newsitem */
$data = $newsitem;
$data['update_time'] = strtotime($data['update_time']);
$object->_create($data);
}
// releases
Database::query('TRUNCATE `releases`');
$query = 'SELECT * FROM `fashist`.`module_news` WHERE `type`=1';
$news = Database::sql2array($query, 'id');
foreach ($news as $id => $newsitem) {
$object = Releases::getInstance()->getById($id);
/* @var $object Release */
$data = $newsitem;
$data['update_time'] = strtotime($data['update_time']);
$object->_create($data);
}
//comments
Database::query('TRUNCATE `comments`');
Database::query('ALTER TABLE `comments` DROP PRIMARY KEY', false);
Database::query('INSERT INTO `comments` (SELECT * FROM `fashist`.`comments`)');
// all releases comments comes to releases comments!
$query = 'UPDATE `comments` SET `table`=\'releases\' WHERE `table`=\'news\' AND `doc_id` IN (SELECT `id` FROM `releases`)';
Database::query($query);
Database::query('ALTER TABLE `hardtechno`.`comments` ADD PRIMARY KEY ( `doc_id` , `table` , `id` ) ');
// upload
exec('rm -rf /home/test.hardtechno.ru/static/upload/news/*', $o);
print_r($o);
exec('rm -rf /home/test.hardtechno.ru/static/upload/avatars/*', $o);
print_r($o);
exec('cp -r /home/hardtechno.ru/upload/news/* /home/test.hardtechno.ru/static/upload/news', $o);
print_r($o);
exec('cp -r /home/hardtechno.ru/upload/avatar/* /home/test.hardtechno.ru/static/upload/avatars', $o);
print_r($o);
exec('chmod 777 -R /home/test.hardtechno.ru/static', $o);
print_r($o);
die('all');