noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
package_repository.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
21
22/**
23 * @file
24 * @brief contains the class Package_Repository
25 */
26
27/**
28 * @brief connect to NOALYSS_PACKAGE and fetch the file web.xml , it displays
29 * content of this file , build the appropriate object for installing
30 */
32{
33
34 protected $content;
35 static $time_cache_second = 3600; // cache time in second
36
37 /**
38 * @see package_repository.test.php
39 */
40 function __construct()
41 {
42 if ( DEBUGNOALYSS > 1) self::$time_cache_second=1;
43 // Check we can resolve the name
44 $host=parse_url(NOALYSS_PACKAGE_REPOSITORY,PHP_URL_HOST);
45 $file=$_ENV['TMP']."/web.xml";
46
47 if ( file_exists($file) ) {
48 $date_time=new \DateTime();
49 $file_tmstamp=filemtime($file);
50
51 $delta=$date_time->getTimestamp() - $file_tmstamp;
52
53 // if file too old , refresh it
54 if ( $delta > self::$time_cache_second ) {
55 $web_repo = file_get_contents(NOALYSS_PACKAGE_REPOSITORY."/web.xml");
56 $f_file= fopen($file,"w+");
57 fwrite($f_file,$web_repo);
58 fclose($f_file);
59 $this->setContent($web_repo);
60 } else {
61 $this->setContent(file_get_contents($file));
62 }
63 } elseif( gethostbyname($host) != $host) {
64 $content=file_get_contents(NOALYSS_PACKAGE_REPOSITORY."/web.xml");
65 $this->content=simplexml_load_string($content);
66 $file=$_ENV['TMP']."/web.xml";
67 $f_file= fopen($file,"w+");
68 fwrite($f_file,$this->content->saveXML());
69 fclose($f_file);
70 } else {
71 $this->content=NULL;
72 }
73
74
75
76 }
77 /**
78 * @return int
79 */
80 public static function getTimeCacheSecond(): int
81 {
82 return self::$time_cache_second;
83 }
84
85 /**
86 * @param int $time_cache_second
87 */
88 public static function setTimeCacheSecond(int $time_cache_second):void
89 {
90 self::$time_cache_second = $time_cache_second;
91
92 }
93
94
95 public function getContent()
96 {
97 return $this->content;
98 }
99
100 /**
101 * @brief set content
102 * @param $content xml file to be parsed
103 * @return Package_Repository
104 */
105 public function setContent($content)
106 {
107 $this->content=simplexml_load_string($content);
108 if ( $this->content==false ) throw new Exception ("XML INVALIDE [$content]",EXC_INVALID);
109 return $this;
110 }
111 /**
112 * @brief check that NOALYSS_HOME exists and is writable
113 */
114 function can_download()
115 {
116 $download_dir=NOALYSS_HOME."/tmp";
117 if (is_dir($download_dir)&&is_writable($download_dir))
118 {
119 return TRUE;
120 }
121 return FALSE;
122 }
123
124 /**
125 * Get info for Noalyss code : version #, announce, path to the last
126 * version
127 */
129 {
130 global $g_user;
131 if ( $this->content == NULL ) {
132 throw new Exception(_("Problème réseau"),10);
133 }
134 switch ($g_user->lang)
135 {
136 case 'fr_FR.utf8':
137 echo "<pre>";
138 echo $this->content->core->description;
139 echo "</pre>";
140
141 break;
142 case 'en_US.utf8':
143 break;
144 case 'nl_NL.utf8':
145 break;
146 }
147 }
148
149 /**
150 * return a SimpleXMLElement of the plugin thanks its code, it returns NULL if no plugin is found
151 * @param string $p_code code of the plugin
152 * @return SimpleXMLElement or NULL if not found
153 */
154 function find_plugin($p_code)
155 {
156 if ( $this->content == NULL ) {
157 throw new Exception(_("Problème réseau"),10);
158 }
159 $a_plugin=$this->content->xpath('//plugins/plugin');
160 $nb_plugin=count($a_plugin);
161 for ($i=0; $i<$nb_plugin; $i++)
162 {
163 if (trim($a_plugin[$i]->code)==$p_code)
164 {
165 return $a_plugin[$i];
166 }
167 }
168 return NULL;
169 }
170
171
172 /**
173 * return a SimpleXMLElement of the db template thanks its code, it returns NULL if no template is found
174 * @param string $p_code code of the template
175 * @return SimpleXMLElement or NULL if not found
176 */
177 function find_template($p_code)
178 {
179 if ( $this->content == NULL ) {
180 throw new Exception(_("Problème réseau"),10);
181 }
182 $a_template=$this->content->xpath('//database_template/dbtemplate');
184 for ($i=0; $i<$nb_template; $i++)
185 {
186 if (trim($a_template[$i]->code)==$p_code)
187 {
188 return $a_template[$i];
189 }
190 }
191 return NULL;
192 }
193
195 {
196 if ( $this->content == NULL ) {
197 throw new Exception(_("Problème réseau"),10);
198 }
199 switch ($p_type)
200 {
201 case "core":
202 // Create an object to download & install the core
203 $obj=new Package_Core("Noalyss", "Core", $this->content->core->path);
204 return $obj;
205 break;
206 case 'template':
207 // create an object to download & install the template
208 $db=$this->find_template($p_id);
209 if ($db == NULL ) {
210 throw new Exception(_("Modèle non trouvé"),1002);
211 }
212 $obj=new Package_Template($db->name,$db->description,$db->path);
213 return $obj;
214 case 'plugin':
215 // create an object to download & install a plugin
216 $plugin = $this->find_plugin($p_id);
217 if ($plugin==NULL)
218 {
219 throw new Exception(_("Extension non trouvée"), 1001);
220 }
221 $obj=new Package_Plugin($plugin->name,$plugin->description,$plugin->path);
222 return $obj;
223 break;
224 case 'contrib':
225 //create an object to download & install a contrib
226 default:
227 break;
228 }
229 }
230 /**
231 * Read xml file from the package
232 * @param string $p_file
233 * @return SimpleXMLElement
234 */
235 public function read_package_xml($p_file)
236 {
237 $dom=new DomDocument('1.0');
238 $dom->load($p_file);
239 $xml=simplexml_import_dom($dom);
240 return $xml;
241 }
242
243}
global $g_user
if no group available , then stop
switch($op2) $xml
catch(Exception $e) $obj
_("actif, passif,charge,...")
else $card content[$j]['j_montant']
$a_plugin
for($e=0;$e< $nb_dirscan;$e++) $nb_plugin
Class Package Core to install the core , if possible.
Manage the installation of plug.
connect to NOALYSS_PACKAGE and fetch the file web.xml , it displays content of this file ,...
static setTimeCacheSecond(int $time_cache_second)
find_template($p_code)
return a SimpleXMLElement of the db template thanks its code, it returns NULL if no template is found
can_download()
check that NOALYSS_HOME exists and is writable
setContent($content)
set content
display_noalyss_info()
Get info for Noalyss code : version #, announce, path to the last version.
read_package_xml($p_file)
Read xml file from the package.
find_plugin($p_code)
return a SimpleXMLElement of the plugin thanks its code, it returns NULL if no plugin is found
Show , download and install template database for accountancy from the Package repository.
const EXC_INVALID
Definition constant.php:358
if( $delta< 0) elseif( $delta==0)
if( $xml==NULL) $a_template