X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fpackages.inc;h=cc387f64425d121491be0cfa0497ad5ed31d4ef8;hb=175a48c5bd73abe16e77fa2cb48ba522f00d1501;hp=a98b8f897ff639628f389d99602fd110f8104cd0;hpb=9e804a1a25b41581b4c0a343879157d732d46db2;p=fa-stable.git diff --git a/includes/packages.inc b/includes/packages.inc index a98b8f89..cc387f64 100644 --- a/includes/packages.inc +++ b/includes/packages.inc @@ -10,6 +10,8 @@ See the License here . ***********************************************************************/ include_once($path_to_root. "/includes/archive.inc"); +include_once($path_to_root. "/includes/remote_url.inc"); +include_once($path_to_root. "/includes/hooks.inc"); define('PKG_CACHE_PATH', $path_to_root.'/modules/_cache'); define('PUBKEY_PATH', $path_to_root); @@ -71,7 +73,8 @@ class package extends gzip_file { $dpackage->extract_files(); //install package in target directory - $success &= $this->support('install'); + $install = hook_invoke($ctrl['Package'], 'install_extension', $dummy); + $success &= $install===null || $install; $success &= count($dpackage->error) == 0; $this->error = array_merge($this->error, $dpackage->error); return $success; @@ -96,7 +99,13 @@ class package extends gzip_file { $success &= copy_files($flist, "$cachepath/_back", $targetdir, true); - $success &= $this->support('uninstall'); + if (strpos($ctrl['InstallPath'], 'modules/') === 0) { // flush module directory + flush_dir($targetdir, true); + rmdir($targetdir); + } + + $uninstall = hook_invoke($ctrl['Package'], 'uninstall_extension', $dummy); + $success &= $uninstall===null || $uninstall; return $success; } @@ -108,23 +117,6 @@ class package extends gzip_file { return true; } - // - // Call special function defined in package install class - // - function support($name, $params = null) - { - $cachepath = $this->options['basedir']; - if (file_exists("$cachepath/_init/init.php")) { - include("$cachepath/_init/init.php"); - if (method_exists($installer, $name)) { - set_include_path("$cachepath/_init".PATH_SEPARATOR.get_include_path()); - - $ret = $installer->$name($params); - return $ret; - } - } - return true; - } } // // Changes field value read from control file (single, or multiline) into @@ -134,8 +126,8 @@ function ufmt_property($key, $value) { // indexes used in output arrays $sub_fields = array( - 'MenuTabs' => array('url', 'access', 'tab_id', 'title', 'section'), - 'MenuEntries' => array('url', 'access', 'tab_id', 'title'), +// 'MenuTabs' => array('url', 'access', 'tab_id', 'title', 'section'), +// 'MenuEntries' => array('url', 'access', 'tab_id', 'title'), ); if (!isset($sub_fields[$key])) return $value==='' ? null : $value; @@ -290,10 +282,10 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey $refresh = true; do{ if (!file_exists($loclist)) { - copy(REPO_URL.'/Release.gz', $loclist); + url_copy(REPO_URL.'/Release.gz', $loclist); $refresh = false; } - $sig = file_get_contents(REPO_URL.'/Release.sig', 'rb'); + $sig = url_get_contents(REPO_URL.'/Release.sig'); $data = file_get_contents($loclist); $cert = file_get_contents(PUBKEY_PATH.'/FA.pem'); if (!openssl_verify($data, $sig, $cert)) { @@ -323,7 +315,7 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey $refresh = true; do{ if (!file_exists($locindex)) { - copy($remoteindex, $locindex); + url_copy($remoteindex, $locindex); $refresh = false; } if ($parms['SHA1sum'] != sha1_file($locindex)) { // check subdir index consistency @@ -359,7 +351,7 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey //download package to temp directory if ($download) { $locname = "$path_to_root/tmp/".$pkg['Filename'].'.pkg'; - copy($pkgfullname, $locname); + url_copy($pkgfullname, $locname); // checking sha1 hash is expensive proces, so chekc the package // consistency just before downloading if ($pkg['SHA1sum'] != sha1_file($locname)) { @@ -461,11 +453,12 @@ function get_languages_list() // function get_extensions_list($type = null) { + global $path_to_root; - if (isset($type) && !is_array($type)) { + if (isset($type) || !is_array($type)) { $type = array($type); } - + $pkgs = get_pkg_or_list($type, null, array( 'Package' => 'package', 'Version' => 'available', @@ -473,22 +466,44 @@ function get_extensions_list($type = null) 'Description' => 'Descr', 'Type' => 'type', 'DefaultStatus'=> 'active', - 'MenuTabs' => 'tabs', - 'MenuEntries' => 'entries', +// 'MenuTabs' => 'tabs', +// 'MenuEntries' => 'entries', 'Encoding' => 'encoding', - 'AccessExtensions' => 'acc_file', +// 'AccessExtensions' => 'acc_file', 'InstallPath' => 'path' )); + // lookup for local extensions + $path = $path_to_root.'/modules/'; + $loc = array(); + $moddir = opendir($path); + + while(false != ($fname = readdir($moddir))) + { + if(!in_array($fname, array('.','..','CVS','_cache')) && is_dir($path.$fname)) + { + if (!isset($pkgs[$fname])) + $pkgs[$fname] = array( + 'package' => $fname, + 'name' => $fname, + 'version' => '', + 'available' => '', + 'type' => 'extension', + 'path' => 'modules/'.$fname, + 'active' => false + ); + } + } + // add/update extensions already installed // - $local = get_company_extensions(); - foreach($local as $extno => $ext) { + $installed = get_company_extensions(); + foreach($installed as $extno => $ext) { if (!in_array($ext['type'], $type)) continue; $ext['local_id'] = $extno; - if (!isset($pkgs[$ext['package']]) || $ext['package'] == '') - $pkgs[] = $ext; - else +// if (!isset($pkgs[$ext['package']]) || $ext['package'] == '') +// $pkgs[] = $ext; +// else $pkgs[$ext['package']] = array_merge($pkgs[$ext['package']], $ext); } ksort($pkgs); @@ -590,17 +605,22 @@ function install_language($pkg_name) write_lang($installed_languages); unlink("$path_to_root/tmp/".$pkg['Filename'].'.pkg'); $Ajax->activate('lang_tbl'); + } else { + display_error(implode('
', $package->error)); + return false; } - + } else { + display_error(sprintf(_("Package '%s' not found."), $pkg_name)); + return false; } - + return true; } //--------------------------------------------------------------------------------------------- // Install/update extension or theme package from repository // function install_extension($pkg_name) { - global $path_to_root, $next_extension_id, $Ajax; + global $path_to_root, $installed_extensions, $next_extension_id, $Ajax; $pkg = get_pkg_or_list(array('extension', 'theme', 'chart'), $pkg_name); if ($pkg) { @@ -610,6 +630,11 @@ function install_extension($pkg_name) $ext_id = array_search_key($pkg['Package'], $local_exts, 'package'); if ($ext_id === null) $ext_id = $next_extension_id++; + else { // remove another already installed package for this language + $old_pkg = $installed_extensions[$ext_id]['package']; + if ($old_pkg) + uninstall_package($old_pkg); + } $ext = array( 'name' => $pkg['Name'], 'package' => $pkg['Package'], @@ -618,12 +643,12 @@ function install_extension($pkg_name) 'active' => true, 'path' => $pkg['InstallPath'], ); - if (isset($pkg['MenuTabs'])) - $ext['tabs'] = $pkg['MenuTabs']; - if (isset($pkg['MenuEntries'])) - $ext['entries'] = $pkg['MenuEntries']; - if (isset($pkg['AccessExtensions'])) - $ext['acc_file'] = $pkg['AccessExtensions']; +// if (isset($pkg['MenuTabs'])) +// $ext['tabs'] = $pkg['MenuTabs']; +// if (isset($pkg['MenuEntries'])) +// $ext['entries'] = $pkg['MenuEntries']; +// if (isset($pkg['AccessExtensions'])) +// $ext['acc_file'] = $pkg['AccessExtensions']; if (isset($pkg['SqlScript'])) $ext['sql'] = $pkg['SqlScript']; $local_exts[$ext_id] = $ext; @@ -635,6 +660,9 @@ function install_extension($pkg_name) display_error(implode('
', $package->error)); return false; } + } else { + display_error(sprintf(_("Package '%s' not found."), $pkg_name)); + return false; } return true; }