@@ -13,19 +13,24 @@ private function extractPackage($package_file) {
1313 $ ret = null ;
1414 $ retval = 0 ;
1515
16+ $ app ->log ('Extracting addon package ' . $ package_file , 0 , false );
17+
1618 $ cmd = 'which unzip ' ;
1719 $ tmp = explode ("\n" , exec ($ cmd , $ ret , $ retval ));
1820 if ($ retval != 0 ) {
21+ $ app ->log ('The unzip command was not found on the server. ' , 2 , false );
1922 throw new AddonInstallerException ('unzip tool not found. ' );
2023 }
2124 $ unzip = reset ($ tmp );
2225 unset($ tmp );
2326 if (!$ unzip ) {
27+ $ app ->log ('Unzip tool was not found. ' , 2 , false );
2428 throw new AddonInstallerException ('unzip tool not found. ' );
2529 }
2630
2731 $ temp_dir = $ app ->system ->tempdir (sys_get_temp_dir (), 'addon_ ' , 0700 );
2832 if (!$ temp_dir ) {
33+ $ app ->log ('Could not create the temp dir. ' , 2 , false );
2934 throw new AddonInstallerException ('Could not create temp dir. ' );
3035 }
3136
@@ -34,9 +39,12 @@ private function extractPackage($package_file) {
3439 $ cmd = $ unzip . ' -d ' . escapeshellarg ($ temp_dir ) . ' ' . escapeshellarg ($ package_file );
3540 exec ($ cmd , $ ret , $ retval );
3641 if ($ retval != 0 ) {
42+ $ app ->log ('Package extraction failed. ' , 2 , false );
3743 throw new AddonInstallerException ('Package extraction failed. ' );
3844 }
3945
46+ $ app ->log ('Extracted to ' . $ temp_dir , 0 , false );
47+
4048 return $ temp_dir ;
4149 }
4250
@@ -46,36 +54,48 @@ private function extractPackage($package_file) {
4654 * @throws AddonInstallerValidationException
4755 */
4856 private function validatePackage ($ path ) {
57+ $ app ->log ('Validating extracted addon at ' . $ path , 0 , false );
58+
4959 if (!is_dir ($ path )) {
60+ $ app ->log ('Invalid path. ' , 2 , false );
5061 throw new AddonInstallerValidationException ('Invalid path. ' );
5162 }
5263
5364 $ ini_file = $ path . '/addon.ini ' ;
5465 if (!is_file ($ ini_file )) {
66+ $ app ->log ('Addon ini file missing. ' , 2 , false );
5567 throw new AddonInstallerValidationException ('Addon ini file missing. ' );
5668 }
5769
70+ $ app ->log ('Parsing ini ' . $ ini_file , 0 , false );
5871 $ ini = parse_ini_file ($ ini_file , true );
5972 if (!$ ini || !isset ($ ini ['addon ' ])) {
73+ $ app ->log ('Ini file could not be read. ' , 2 , false );
6074 throw new AddonInstallerValidationException ('Ini file is missing addon section. ' );
6175 }
6276
6377 $ addon = $ ini ['addon ' ];
6478 if (!isset ($ addon ['ident ' ]) || !isset ($ addon ['name ' ]) || !isset ($ addon ['version ' ])) {
79+ $ app ->log ('Addon data in ini file missing or invalid. ' , 2 , false );
6580 throw new AddonInstallerValidationException ('Ini file is missing addon ident/name/version. ' );
6681 }
6782
6883 $ class_file = $ path . '/ ' . $ addon ['ident ' ] . '.addon.php ' ;
6984 if (!is_file ($ class_file )) {
85+ $ app ->log ('Base class file in addon not found ' , 2 , false );
7086 throw new AddonInstallerValidationException ('Package is missing main addon class. ' );
7187 }
7288
7389 if (isset ($ ini ['ispconfig ' ]['version.min ' ]) && $ ini ['ispconfig ' ]['version.min ' ] && version_compare ($ ini ['ispconfig ' ]['version.min ' ], ISPC_APP_VERSION , '> ' )) {
90+ $ app ->log ('ISPConfig version too low for this addon. ' , 2 , false );
7491 throw new AddonInstallerValidationException ('Addon requires at least ISPConfig version ' . $ ini ['ispconfig ' ]['version.min ' ] . '. ' );
7592 } elseif (isset ($ ini ['ispconfig ' ]['version.max ' ]) && $ ini ['ispconfig ' ]['version.max ' ] && version_compare ($ ini ['ispconfig ' ]['version.min ' ], ISPC_APP_VERSION , '< ' )) {
93+ $ app ->log ('ISPConfig version too high for this addon. ' , 2 , false );
7694 throw new AddonInstallerValidationException ('Addon allows at max ISPConfig version ' . $ ini ['ispconfig ' ]['version.max ' ] . '. ' );
7795 }
7896
97+ $ app ->log ('Loaded addon installer ' . $ class_file , 0 , false );
98+
7999 $ addon ['class_file ' ] = $ class_file ;
80100 $ addon ['class_name ' ] = substr (basename ($ class_file ), 0 , -10 ) . '_addon_installer ' ;
81101
@@ -92,21 +112,30 @@ private function getInstalledAddonVersion($ident) {
92112 // check for previous version
93113 if (is_dir ($ addon_path . '/ ' . $ ident ) && is_file ($ addon_path . '/ ' . $ ident . '/addon.ini ' )) {
94114 $ addon = parse_ini_file ($ addon_path . '/ ' . $ ident . '/addon.ini ' , true );
115+ if ($ addon && isset ($ addon ['addon ' ])) {
116+ $ addon = $ addon ['addon ' ]; // ini section
117+ } else {
118+ $ addon = false ;
119+ }
95120 if (!$ addon || !isset ($ addon ['version ' ]) || !isset ($ addon ['ident ' ]) || $ addon ['ident ' ] != $ ident ) {
96- throw new AddonInstallerException ('Installed app found but it is invalid. ' );
121+ $ app ->log ('Could not get version of installed addon. ' , 2 , false );
122+ throw new AddonInstallerException ('Installed app ' . $ ident . ' found but it is invalid. ' );
97123 }
98124
99125 $ file_version = $ addon ['version ' ];
126+ $ app ->log ('Installed version of addon ' . $ ident . ' is ' . $ file_version , 0 , false );
100127 }
101128
102129 $ check = $ app ->db ->queryOneRecord ('SELECT `addon_version` FROM `addons` WHERE `addon_ident` = ? ' , $ ident );
103130 if ($ check && $ check ['addon_version ' ]) {
104131 $ db_version = $ check ['addon_version ' ];
132+ $ app ->log ('Installed version of addon ' . $ ident . ' (in db) is ' . $ db_version . '. ' , 0 , false );
105133 }
106134
107135 if (!$ file_version && !$ db_version ) {
108136 return false ;
109137 } elseif ($ file_version != $ db_version ) {
138+ $ app ->log ('Version mismatch between ini file and database ( ' . $ file_version . ' != ' . $ db_version . '). ' , 0 , false );
110139 throw new AddonInstallerException ('Addon version mismatch in database ( ' . $ db_version . ') and file system ( ' . $ file_version . '). ' );
111140 }
112141
@@ -126,40 +155,52 @@ public function installAddon($package_file, $force = false) {
126155 $ app ->load ('ispconfig_addon_installer_base ' );
127156
128157 if (!is_file ($ package_file )) {
158+ $ app ->log ('Package file not found: ' . $ package_file , 2 , false );
129159 throw new AddonInstallerException ('Package file not found. ' );
130160 } elseif (substr ($ package_file , -4 ) !== '.pkg ' ) {
161+ $ app ->log ('Invalid package file: ' . $ package_file , 2 , false );
131162 throw new AddonInstallerException ('Invalid package file. ' );
132163 }
133164
134165 $ tmp_dir = $ this ->extractPackage ($ package_file );
135166 if (!$ tmp_dir ) {
136167 // extracting failed
168+ $ app ->log ('Package extraction failed. ' , 2 , false );
137169 throw new AddonInstallerException ('Package extraction failed. ' );
138170 }
139171
140172 $ addon = $ this ->validatePackage ($ tmp_dir );
141173 if (!$ addon ) {
142174 throw new AddonInstallerException ('Package validation failed. ' );
143175 }
176+ $ app ->log ('Package validated. ' , 0 , false );
144177
145178 $ is_update = false ;
146179 $ previous = $ this ->getInstalledAddonVersion ($ addon ['ident ' ]);
147180 if ($ previous !== false ) {
148181 // this is an update
149182 if (version_compare ($ previous , $ addon ['version ' ], '> ' ) && $ force !== true ) {
183+ $ app ->log ('Installed version is newer than the one to install and --force not used. ' , 2 , false );
150184 throw new AddonInstallerException ('Installed version is newer than the one to install. ' );
151185 } elseif (version_compare ($ previous , $ addon ['version ' ], '= ' ) && $ force !== true ) {
186+ $ app ->log ('Installed version is the same as the one to install and --force not used. ' , 2 , false );
152187 throw new AddonInstallerException ('Installed version is the same as the one to install. ' );
153188 }
154189 $ is_update = true ;
155190 }
191+
192+ $ app ->log ('Including package class file ' . $ addon ['class_file ' ], 0 , false );
193+
156194 include $ addon ['class_file ' ];
157- if (!class_exists ($ addon ['class_name ' ])) {
195+ $ class_name = $ addon ['class_name ' ];
196+ if (!class_exists ($ class_name )) {
197+ $ app ->log ('Class name ' . $ class_name . ' not found in class file ' . $ addon ['class_file ' ], 2 , false );
158198 throw new AddonInstallerException ('Could not find main class in addon file. ' );
159199 }
160200
161- $ class_name = $ addon ['class_name ' ];
162201 /* @var $inst ispconfig_addon_installer_base */
202+ $ app ->log ('Instanciating installer class ' . $ class_name , 0 , false );
203+
163204 $ inst = new $ class_name ();
164205 $ inst ->setAddonName ($ addon ['name ' ]);
165206 $ inst ->setAddonIdent ($ addon ['ident ' ]);
@@ -178,6 +219,7 @@ public function installAddon($package_file, $force = false) {
178219
179220 exec ('rm -rf ' . escapeshellarg ($ tmp_dir ));
180221
222+ $ app ->log ('Installation completed. ' , 0 , false );
181223 return true ;
182224 }
183225
0 commit comments