source: branches/dev/html/admin/system/update.php @ 17

Revision 17, 7.4 KB checked in by uehara, 17 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../require.php");
8
9//¥Ú¡¼¥¸´ÉÍý¥¯¥é¥¹
10class LC_Page {
11    //¥³¥ó¥¹¥È¥é¥¯¥¿
12    function LC_Page() {
13        //¥á¥¤¥ó¥Æ¥ó¥×¥ì¡¼¥È¤Î»ØÄê
14        $this->tpl_mainpage = 'system/update.tpl';
15        $this->tpl_subnavi = 'system/subnavi.tpl';
16        $this->tpl_mainno = 'system';       
17        $this->tpl_subno = 'update';
18        $this->tpl_subtitle = '¥¢¥Ã¥×¥Ç¡¼¥È´ÉÍý';
19    }
20}
21
22$objPage = new LC_Page();
23$objView = new SC_AdminView();
24$objQuery = new SC_Query();
25
26// ¥»¥Ã¥·¥ç¥ó¥¯¥é¥¹
27$objSess = new SC_Session();
28// ǧ¾Ú²ÄÈݤÎȽÄê
29sfIsSuccess($objSess);
30
31switch($_POST['mode']) {
32// ¥¢¥Ã¥×¥Ç¡¼¥È¾ðÊó¥Õ¥¡¥¤¥ë¤ò¼èÆÀ
33case 'edit':
34    // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
35    lfLoadUpdateList();
36    break;
37// ¥¤¥ó¥¹¥È¡¼¥ë
38case 'install':
39    // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
40    lfLoadUpdateList();
41    // ¥â¥¸¥å¡¼¥ë·´¤Î¥¤¥ó¥¹¥È¡¼¥ë
42    lfInstallModule();
43    break;
44// ¥¢¥ó¥¤¥ó¥¹¥È¡¼¥ë
45case 'uninstall':
46    // ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
47    lfLoadUpdateList();
48    // ¥â¥¸¥å¡¼¥ë·´¤Î¥¤¥ó¥¹¥È¡¼¥ë   
49    lfUninstallModule();
50    break;
51default:
52    break;
53}
54
55$col = "module_id, module_name, now_version, latest_version, module_explain, create_date, release_date";
56$objQuery->setorder("module_id");
57$objPage->arrUpdate = $objQuery->select($col, "dtb_update");
58
59$objView->assignobj($objPage);      //ÊÑ¿ô¤ò¥Æ¥ó¥×¥ì¡¼¥È¤Ë¥¢¥µ¥¤¥ó¤¹¤ë
60$objView->display(MAIN_FRAME);      //¥Æ¥ó¥×¥ì¡¼¥È¤Î½ÐÎÏ
61//-------------------------------------------------------------------------------------------------------
62// ¹¹¿·¥Õ¥¡¥¤¥ë¤Î¼èÆÀ
63function lfCopyUpdateFile($file) {
64    global $objPage;
65   
66    $src_path = sfRmDupSlash(UPDATE_HTTP . $file . ".txt");
67    $dst_path = sfRmDupSlash(UPDATE_PATH . $file);
68    $flg_ok = true; // ½èÍý¤ÎÀ®¸ùȽÄê
69   
70    $src_fp = @fopen($src_path, "rb");
71   
72    if(!$src_fp) {
73        sfErrorHeader(">> " . $src_path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
74        $flg_ok = false;
75    } else {
76        // ¥Õ¥¡¥¤¥ë¤ò¤¹¤Ù¤ÆÆɤ߹þ¤à
77        $contents = '';
78        while (!feof($src_fp)) {
79            $contents .= fread($src_fp, 1024);
80        }
81        fclose($src_fp);
82       
83        // ¥Ç¥£¥ì¥¯¥È¥êºîÀ®¤ò»î¤ß¤ë
84        lfMakeDirectory($dst_path);
85        // ¥Õ¥¡¥¤¥ë½ñ¹þ¤ß       
86        $dst_fp = @fopen($dst_path, "wb");
87        if(!$dst_fp) {
88            sfErrorHeader(">> " . $dst_path . "¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
89            $flg_ok = false;
90        } else {
91            fwrite($dst_fp, $contents);
92            fclose($dst_fp);
93        }
94    }
95   
96    if($flg_ok) {
97        $objPage->update_mess.= ">> " . $dst_path . "¡§¥³¥Ô¡¼À®¸ù<br>";
98    } else {
99        $objPage->update_mess.= ">> " . $dst_path . "¡§¥³¥Ô¡¼¼ºÇÔ<br>";     
100    }
101   
102    return $flg_ok;
103}
104
105// ¤¹¤Ù¤Æ¤Î¥Ñ¥¹¤Î¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤¹¤ë
106function lfMakeDirectory($path) {
107    $pos = 0;
108    $cnt = 0;               // ̵¸Â¥ë¡¼¥×Âкö
109    $len = strlen($path);   // ̵¸Â¥ë¡¼¥×Âкö
110   
111    while($cnt <= $len) {
112        $pos = strpos($path, "/", $pos);
113        // ¤³¤³¤Ç¤ÎȽÄê¤Ï¡¢Åù¹æ3¤Ä¤ò»ÈÍÑ
114        if($pos === false) {
115            // ¥¹¥é¥Ã¥·¥å¤¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¥ë¡¼¥×¤«¤éÈ´¤±¤ë
116            break;
117        }
118        $pos++; // ʸ»úȯ¸«°ÌÃÖ¤ò°ìʸ»ú¿Ê¤á¤ë
119        $dir = substr($path, 0, $pos);
120       
121        // ¤¹¤Ç¤Ë¸ºß¤¹¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë
122        if(!file_exists($dir)) {
123            mkdir($dir);
124        }
125        $cnt++; // ̵¸Â¥ë¡¼¥×Âкö
126    }
127}
128
129// ¹¹¿·¾ðÊó¤òºÇ¿·¤Ë¤¹¤ë
130function lfLoadUpdateList() {
131    $objQuery = new SC_Query();
132    $path = UPDATE_HTTP . "update.txt";
133    $fp = @fopen($path, "rb");
134   
135    if(!$fp) {
136        sfErrorHeader(">> " . $path . "¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
137    } else {
138        while (!feof($fp)) {
139            $arrCSV = fgetcsv($fp, UPDATE_CSV_LINE_MAX);
140           
141            if(ereg("^#", $arrCSV[0])) {
142                continue;
143            }
144                       
145            // ¥«¥é¥à¿ô¤¬Àµ¾ï¤Ç¤¢¤Ã¤¿¾ì¹ç¤Î¤ß
146            if(count($arrCSV) == UPDATE_CSV_COL_MAX) {
147                // ¼èÆÀ¤·¤¿¥¢¥Ã¥×¥Ç¡¼¥È¾ðÊó¤òDB¤Ë½ñ¤­¹þ¤à
148                $sqlval['module_id'] = $arrCSV[0];
149                $sqlval['module_name'] = $arrCSV[1];
150                $sqlval['latest_version'] = $arrCSV[3];
151                $sqlval['module_explain'] = $arrCSV[4];
152                $sqlval['main_php'] = $arrCSV[5];
153                $sqlval['extern_php'] = $arrCSV[6];
154                $sqlval['install_sql'] = $arrCSV[7];
155                $sqlval['uninstall_sql'] = $arrCSV[8];             
156                $sqlval['other_files'] = $arrCSV[9];
157                $sqlval['del_flg'] = $arrCSV[10];
158                $sqlval['update_date'] = "now()";
159                $sqlval['release_date'] = $arrCSV[12];
160                // ´û¸¥ì¥³¡¼¥É¤Î¥Á¥§¥Ã¥¯
161                $cnt = $objQuery->count("dtb_update", "module_id = ?", array($sqlval['module_id']));
162                if($cnt > 0) {
163                    // ¤¹¤Ç¤Ë¼èÆÀ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¹¹¿·¤¹¤ë¡£
164                    $objQuery->update("dtb_update", $sqlval, "module_id = ?", array($sqlval['module_id']));
165                } else {
166                    // ¿·µ¬¥ì¥³¡¼¥É¤ÎÄɲÃ
167                    $sqlval['create_date'] = "now()";
168                    $objQuery->insert("dtb_update", $sqlval);
169                }
170            }
171        }
172        fclose($fp);
173    }
174}
175
176// ¥¤¥ó¥¹¥È¡¼¥ë½èÍý
177function lfInstallModule() {
178    global $objPage;
179   
180    $objQuery = new SC_Query();
181    $arrRet = $objQuery->select("module_id, extern_php, other_files, install_sql, latest_version", "dtb_update", "module_id = ?", array($_POST['module_id']));
182    $flg_ok = true; // ½èÍý¤ÎÀ®¸ùȽÄê
183   
184    if(count($arrRet) > 0) {
185        $arrFiles = array();
186        if($arrRet[0]['other_files'] != "") {
187            $arrFiles = split("\|", $arrRet[0]['other_files']);
188        }
189        $arrFiles[] = $arrRet[0]['extern_php'];
190        foreach($arrFiles as $val) {
191            // ¹¹¿·¥Õ¥¡¥¤¥ë¤Î¼èÆÀ
192            $ret=lfCopyUpdateFile($val);
193            if(!$ret) {
194                $flg_ok = false;
195            }
196        }
197    } else {
198        sfErrorHeader(">> Âоݤε¡Ç½¤Ï¡¢ÇÛÉÛ¤ò½ªÎ»¤·¤Æ¤ª¤ê¤Þ¤¹¡£");
199        $flg_ok = false;
200    }
201   
202    // ɬÍפÊSQLʸ¤Î¼Â¹Ô
203    if($arrRet[0]['install_sql'] != "") {
204        // SQLʸ¼Â¹Ô¡¢¥Ñ¥é¡¼¥á¡¼¥¿¤Ê¤·¡¢¥¨¥é¡¼Ìµ»ë
205        $arrInstallSql = split(";",$arrRet[0]['install_sql']);
206        foreach($arrInstallSql as $key => $val){
207            if (trim($val) != ""){
208                $ret = $objQuery->query(trim($val),"",true);
209            }
210        }
211        if(DB::isError($ret)) {
212            // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
213            ereg("\[(.*)\]", $ret->userinfo, $arrKey);
214            $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
215            $objPage->update_mess.= $arrKey[0] . "<br>";
216            $flg_ok = false;
217        } else {
218            $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤ò¹Ô¤¤¤Þ¤·¤¿¡£<br>";
219        }
220    }
221   
222    if($flg_ok) {
223        $sqlval['now_version'] = $arrRet[0]['latest_version'];
224        $sqlval['update_date'] = "now()";
225        $objQuery->update("dtb_update", $sqlval, "module_id = ?", array($arrRet[0]['module_id']));
226    }
227}
228
229// ¥¢¥ó¥¤¥ó¥¹¥È¡¼¥ë½èÍý
230function lfUninstallModule() {
231    global $objPage;
232   
233    $objQuery = new SC_Query();
234    $arrRet = $objQuery->select("module_id, extern_php, other_files, install_sql, uninstall_sql, latest_version", "dtb_update", "module_id = ?", array($_POST['module_id']));
235    $flg_ok = true; // ½èÍý¤ÎÀ®¸ùȽÄê
236   
237    if(count($arrRet) > 0) {
238        $arrFiles = array();
239        if($arrRet[0]['other_files'] != "") {
240            $arrFiles = split("\|", $arrRet[0]['other_files']);
241        }
242        $arrFiles[] = $arrRet[0]['extern_php'];
243        foreach($arrFiles as $val) {
244            $path = DATA_PATH . $val;
245            if(file_exists($path)) {
246                // ¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë
247                if(unlink($path)) {
248                    $objPage->update_mess.= ">> " . $path . "¡§ºï½üÀ®¸ù<br>";
249                } else {
250                    $objPage->update_mess.= ">> " . $path . "¡§ºï½ü¼ºÇÔ<br>";
251                }
252            }
253        }
254       
255        // ɬÍפÊSQLʸ¤Î¼Â¹Ô
256        if($arrRet[0]['uninstall_sql'] != "") {
257            // SQLʸ¼Â¹Ô¡¢¥Ñ¥é¡¼¥á¡¼¥¿¤Ê¤·¡¢¥¨¥é¡¼Ìµ»ë
258            $ret = $objQuery->query($arrRet[0]['uninstall_sql'],"",true);
259            if(DB::isError($ret)) {
260                // ¥¨¥é¡¼Ê¸¤ò¼èÆÀ¤¹¤ë
261                ereg("\[(.*)\]", $ret->userinfo, $arrKey);
262                $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£<br>";
263                $objPage->update_mess.= $arrKey[0] . "<br>";
264                $flg_ok = false;
265            } else {
266                $objPage->update_mess.=">> ¥Æ¡¼¥Ö¥ë¹½À®¤ÎÊѹ¹¤ò¹Ô¤¤¤Þ¤·¤¿¡£<br>";
267            }
268        }       
269    } else {
270        sfErrorHeader(">> Âоݤε¡Ç½¤Ï¡¢ÇÛÉÛ¤ò½ªÎ»¤·¤Æ¤ª¤ê¤Þ¤¹¡£");
271    }
272   
273    if($flg_ok) {
274        // ¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤òºï½ü¤¹¤ë¡£
275        $sqlval['now_version'] = "";
276        $sqlval['update_date'] = "now()";
277        $objQuery->update("dtb_update", $sqlval, "module_id = ?", array($arrRet[0]['module_id']));
278    }
279}
280
281
282?>
Note: See TracBrowser for help on using the repository browser.