root/dev/common/admin_sync.php @ 162

Revision 162, 5.3 KB (checked in by exi, 14 years ago)

Added externalids to autoupgrade code.
Added custom headers to the http_class.
Added an option to set the socket timeout when using the http_class.
Pushed version to 1.2.2 in globals.php.
Fixed a bug in the battle parser which prevented it from parsing kills of the last day.
Added code to the synchronization module so it can handle item value updates as well.
Changed killists so they don't list kills as a kill anymore where an corp/alliance member has been killed, right, those are now pure losses. This should also resolve an issue with the battle parser going mad.

Line 
1<?php
2require_once("class.page.php");
3require_once("class.contract.php");
4require_once("admin_menu.php");
5require_once('class.http.php');
6
7$page = new Page();
8$page->setAdmin();
9$page->setTitle("Administration - Synchronization");
10
11if ($_REQUEST['do'] == 'sync')
12{
13    $http = new http_request(KB_SYNCURL);
14    $fp = $http->connect();
15    if (!$fp)
16    {
17        $html .= "Could not connect to Server:<br/>\n";
18        $html .= $http-getError();
19
20        $page->addContext($menubox->generate());
21        $page->setContent($html);
22        $page->generate();
23        return;
24    }
25
26    $content_file = 'DATA_START';
27    $qry = new DBQuery();
28    $qry->execute("select plt_name, plt_externalid from kb3_pilots where plt_externalid != 0");
29    while ($data = $qry->getRow())
30    {
31        $content_file .= '!'.$data['plt_name'].'|'.$data['plt_externalid'].'-';
32    }
33
34    $content_file .= 'ITEMS_START';
35    $qry->execute("select itm_name, itm_externalid, itm_value from kb3_items where itm_value != 0");
36    while ($data = $qry->getRow())
37    {
38        $content_file .= '§'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$data['itm_value'].'-';
39    }
40
41    $content_file = gzdeflate($content_file);
42
43    $http->set_postdata('data', $content_file);
44    $http->set_useragent("EVE-KB SYNC (VER ".KB_VERSION.")");
45    $http->set_header('X-KBHost: '.base64_encode(KB_HOST));
46    $http->setSockettimeout(30);
47    $file = $http->get_content();
48    $header = $http->get_header();
49
50    preg_match("/X-KBVersion: (.*)/", $header, $match);
51    $version = explode('.', trim($match[1]));
52    $recv = $http->get_recv();
53    $sended = $http->get_sent();
54
55    // the response ($file) contains ids new to us
56    $data = @gzinflate($file);
57    if ($data == false)
58    {
59        $html .= "getting compressed data failed, server response was:<br><pre>\n";
60        $html .= $file."</pre>\n";
61    }
62    else
63    {
64        unset($file);
65
66        // get all names we'll find
67        preg_match_all("^!(.*?)\|(.*?)-^", $data, $matches);
68        $results = count($matches[1]);
69        $update = new DBQuery();
70        for ($i = 0; $i<$results; $i++)
71        {
72            $update->execute("update kb3_pilots set plt_externalid='".addslashes($matches[2][$i])."' where plt_name='".addslashes($matches[1][$i])."' limit 1");
73        }
74        $html .= "Synchronization complete, got $results new ids from server running version ".$version[0].'.'.$version[1].'.'.$version[2].'.<br/>';
75
76        if (isset($_REQUEST['itm_update']))
77        {
78            preg_match_all('^§(.*?)\|(.*?)\|(.*?)-^', $data, $matches);
79            unset($data);
80            $results = count($matches[1]);
81            for ($i = 0; $i<$results; $i++)
82            {
83                $update->execute("update kb3_items set itm_externalid='".addslashes($matches[2][$i])."', itm_value='".addslashes($matches[3][$i])."' where itm_name='".addslashes($matches[1][$i])."' limit 1");
84            }
85            if ($results == 0)
86            {
87                $html .= 'No items fetched, itm_sync_module may be offline.<br/>';
88            }
89            else
90            {
91                $html .= $results.' item prices have been fetched.<br/>';
92            }
93        }
94
95        $html .= "Sent ".round($sended/1024, 2)." kB and received ".round($recv/1024, 2)." kB of data.<br>\n";
96        $html .= '<a href="?a=admin_sync">Back</a>';
97
98        // check for updates here
99        // we might move this to a new/second point some time
100        $ownversion = explode('.', KB_VERSION);
101        if ($version[1] > $ownversion[1] && $version[1] % 2 == 1)
102        {
103            // test for new minor updates below the dev-version
104            if ($version[1]-1 > $ownversion[1])
105            {
106                $upgrade = true;
107            }
108        }
109        elseif ($version[1] > $ownversion[1] && $version[1] % 2 == 0)
110        {
111            // we get here in case there is a new minor version thats not a dev
112            $upgrade = true;
113        }
114        if ($version[0] > $ownversion[0] || $upgrade)
115        {
116            $html .= "Looks like your Killboard version is pretty old, perhaps you want to upgrade it ?<br/>\n";
117            $html .= "Check the <a href='http://www.eve-dev.net/forums/viewforum.php?f=2'>EVE-Dev Forums</a> for new releases and additional information<br>\n";
118        }
119    }
120}
121else
122{
123    $html .= 'You can synchronize your external characterids for the portrait generation with the EVE-Dev.org-Server here.<br>';
124    $html .= 'Your Server will try to contact <i>"'.KB_SYNCURL.'"</i> to exchange the data.<br>';
125    $html .= 'One synchronization every one or two weeks should be enough.<br>';
126    $html .= 'Please don\'t abuse this free service!<br>';
127    $html .= '<form id="options" name="options" method="post" action="?a=admin_sync">';
128    $html .= "<table class=kb-subtable>";
129    $html .= "<tr><td width=120><b>Update item values</b></td><td><input type=checkbox name=itm_update id=itm_update";
130    $html .= " checked=\"checked\"></td></tr>";
131    $html .= '<input type="hidden" name="do" value="sync">';
132    $html .= '<tr><td width=120></td><td><input type=submit name=submit value="Synchronize now"></td></tr></table></form>';
133}
134$page->addContext($menubox->generate());
135$page->setContent($html);
136$page->generate();
137?>
Note: See TracBrowser for help on using the browser.