/**
  * Retrieve all the extension information for all the extensions
  * in extension directory. Beware, we're relying on scandir's 
  * extension retrieval order here, array indices will be used as 
  * ids for extensions that are not installed later on.
  * 
  * @access private
  * @return array list of extensions
  */
 private function _discoverAvailable()
 {
     require_once 'CRM/Core/Extensions/Extension.php';
     $result = array();
     $e = scandir($this->_extDir);
     foreach ($e as $dc => $name) {
         $dir = $this->_extDir . DIRECTORY_SEPARATOR . $name;
         $infoFile = $dir . DIRECTORY_SEPARATOR . self::EXT_INFO_FILENAME;
         if (is_dir($dir) && file_exists($infoFile)) {
             $ext = new CRM_Core_Extensions_Extension($name);
             $ext->readXMLInfo();
             $result[] = $ext;
         }
     }
     return $result;
 }
 public function installFiles()
 {
     $config = CRM_Core_Config::singleton();
     $zip = new ZipArchive();
     $res = $zip->open($this->tmpFile);
     if ($res === TRUE) {
         $zipSubDir = CRM_Utils_Zip::guessBasedir($zip, $this->key);
         if ($zipSubDir === FALSE) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension: bad directory structure') . '<br/>');
             return FALSE;
         }
         $path = $config->extensionsDir . DIRECTORY_SEPARATOR . 'tmp';
         $extractedZipPath = $path . DIRECTORY_SEPARATOR . $zipSubDir;
         if (is_dir($extractedZipPath)) {
             if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
                 CRM_Core_Session::setStatus(ts('Unable to extract the extension: %1 cannot be cleared', array(1 => $extractedZipPath)) . '<br/>');
                 return FALSE;
             }
         }
         if (!$zip->extractTo($path)) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension to %1.', array(1 => $path)) . '<br/>');
             return FALSE;
         }
         $zip->close();
     } else {
         CRM_Core_Session::setStatus('Unable to extract the extension.');
         return FALSE;
     }
     $filename = $extractedZipPath . DIRECTORY_SEPARATOR . 'info.xml';
     if (!is_readable($filename)) {
         CRM_Core_Session::setStatus(ts('Failed reading data from %1 during installation', array(1 => $filename)) . '<br/>');
         return FALSE;
     }
     $newxml = file_get_contents($filename);
     if (empty($newxml)) {
         CRM_Core_Session::setStatus(ts('Failed reading data from %1 during installation', array(1 => $filename)) . '<br/>');
         return FALSE;
     }
     $check = new CRM_Core_Extensions_Extension($this->key . ".newversion");
     $check->readXMLInfo($newxml);
     if ($check->version != $this->version) {
         CRM_Core_Error::fatal('Cannot install - there are differences between extdir XML file and archive XML file!');
     }
     // Why is this a copy instead of a move?
     CRM_Utils_File::copyDir($extractedZipPath, $config->extensionsDir . DIRECTORY_SEPARATOR . $this->key);
     if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
         CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $extractedZipPath)) . '<br/>');
     }
     return TRUE;
 }