/**
  * Scan Smarty plugins directories and relocate custom plugins to correct location
  */
 public function replaceCustomSmartyPlugins()
 {
     // Step 1: scan vendor/Smarty/plugin directory to get a list of system plugins
     $vendorSmartyPluginsList = array();
     $vendorSmartyPluginsPath = 'vendor/Smarty/plugins/';
     $failedToCopySmartyPluginsList = array();
     $customSmartyPluginsPaths = array('include/Smarty/plugins/', 'custom/include/Smarty/plugins/');
     $includeSmartyPluginsPath = 'include/SugarSmarty/plugins/';
     $correctCustomSmartyPluginsPath = 'custom/include/SugarSmarty/plugins/';
     if (is_dir($vendorSmartyPluginsPath)) {
         $iter = new FilesystemIterator($vendorSmartyPluginsPath, FilesystemIterator::UNIX_PATHS);
         foreach ($iter as $item) {
             if ($item->getFileName() == '.' || $item->getFileName() == '..' || $item->isDir() || $item->getExtension() != 'php') {
                 continue;
             }
             $filename = $item->getFilename();
             $vendorSmartyPluginsList[] = $filename;
         }
     }
     // Step 2: scan custom plugin directories and relocate ONLY custom plugins to correct location
     foreach ($customSmartyPluginsPaths as $customSmartyPluginsPath) {
         if (is_dir($customSmartyPluginsPath)) {
             $iter = new FilesystemIterator($customSmartyPluginsPath, FilesystemIterator::UNIX_PATHS);
             foreach ($iter as $item) {
                 if ($item->getFilename() == '.' || $item->getFilename() == '..' || $item->isDir() || $item->getExtension() != 'php') {
                     continue;
                 }
                 $file = $item->getPathname();
                 if (!in_array($item->getFilename(), $vendorSmartyPluginsList) && !is_file($includeSmartyPluginsPath . $item->getFilename())) {
                     $this->log("Copy custom plugin {$file} to {$correctCustomSmartyPluginsPath}");
                     if (!sugar_is_dir($correctCustomSmartyPluginsPath)) {
                         mkdir_recursive($correctCustomSmartyPluginsPath);
                     }
                     if (copy_recursive($file, $correctCustomSmartyPluginsPath . $item->getFilename())) {
                         $this->upgrader->fileToDelete($file);
                     } else {
                         $failedToCopySmartyPluginsList[] = $file;
                     }
                 }
             }
         }
     }
     //Step 3: remove all files from custom Smarty plugins destinations except the {$correctCustomSmartyPluginsPath}
     if (empty($failedToCopySmartyPluginsList)) {
         foreach ($customSmartyPluginsPaths as $customSmartyPluginsPath) {
             if (is_dir($customSmartyPluginsPath)) {
                 $this->log("Path {$customSmartyPluginsPath} is deleted from custom plugins directory due to a relocation of vendors");
                 rmdir_recursive($customSmartyPluginsPath);
             }
         }
     } else {
         foreach ($failedToCopySmartyPluginsList as $failedToCopySmartyPluginsItem) {
             $this->log("File {$failedToCopySmartyPluginsItem} cannot be copied to new location automatically");
         }
     }
 }
Beispiel #2
0
 public function tearDown()
 {
     parent::tearDown();
     if ($this->packageExists) {
         //Copy original contents back in
         copy_recursive('custom/modules/' . $this->package . '_bak', 'custom/modules/' . $this->package);
         rmdir_recursive('custom/modules/' . $this->package . '_bak');
     } else {
         rmdir_recursive('custom/modules/' . $this->package);
     }
     unset($_SESSION['avail_modules'][$this->package]);
 }
 /**
  * backup
  * Private method to handle backing up the file to custom/backup directory
  * 
  * @param $file File or directory to backup to custom/backup directory
  */
 protected function backup($file)
 {
     $basename = basename($file);
     $basepath = str_replace($basename, '', $file);
     if (!empty($basepath) && !file_exists('custom/backup/' . $basepath)) {
         mkdir_recursive('custom/backup/' . $basepath);
     }
     if (is_dir($file)) {
         copy_recursive($file, 'custom/backup/' . $file);
     } else {
         copy($file, 'custom/backup/' . $file);
     }
 }
Beispiel #4
0
function copy_recursive($source, $dest)
{
    if (is_file($source)) {
        return copy($source, $dest);
    }
    if (!sugar_is_dir($dest, 'instance')) {
        sugar_mkdir($dest);
    }
    $status = true;
    $d = dir($source);
    while ($f = $d->read()) {
        if ($f == "." || $f == "..") {
            continue;
        }
        $status &= copy_recursive("{$source}/{$f}", "{$dest}/{$f}");
    }
    $d->close();
    return $status;
}
Beispiel #5
0
/**
 * ディレクトリを再帰的にコピー
 *
 * @param string $src
 * @param string $dst
 */
function copy_recursive($src, $dst)
{
    // In case you'd like to delete exsiting files, you should call rmdir_recursive..
    if (file_exists($dst)) {
        rmdir_recursive($dst);
    }
    if (is_dir($src)) {
        mkdir($dst);
        $files = scandir($src);
        foreach ($files as $file) {
            if ($file != "." && $file != "..") {
                copy_recursive("{$src}/{$file}", "{$dst}/{$file}");
            }
        }
    } else {
        if (file_exists($src)) {
            copy($src, $dst);
        }
    }
}
function copy_recursive($src, $dst)
{
    //if (file_exists($dst)) rrmdir($dst);
    if (is_dir($src)) {
        if (!file_exists($dst)) {
            mkdir($dst);
        }
        //mkdir($dst);
        $files = scandir($src);
        foreach ($files as $file) {
            // ignore .svn directories
            if ($file != "." && $file != ".." && $file != '.svn') {
                copy_recursive("{$src}/{$file}", "{$dst}/{$file}");
            }
        }
    } else {
        if (file_exists($src)) {
            copy($src, $dst);
        }
    }
}
Beispiel #7
0
function copy_recursive($source, $target, $excludes = array())
{
    if (is_dir($source)) {
        mkdir($target);
        $d = dir($source);
        while (false !== ($entry = $d->read())) {
            if ('.' === $entry or '..' === $entry or in_array($entry, $excludes)) {
                continue;
            }
            $Entry = $source . '/' . $entry;
            if (is_dir($Entry)) {
                copy_recursive($Entry, $target . '/' . $entry, $excludes);
                continue;
            }
            copy($Entry, $target . '/' . $entry);
        }
        $d->close();
    } else {
        copy($source, $target);
    }
}
Beispiel #8
0
function copy_recursive($source, $dest)
{
    if (is_dir($source)) {
        $dirHandle = opendir($source);
        while ($file = readdir($dirHandle)) {
            if (!is_dir($dest)) {
                mkdir($dest);
            }
            if ($file != "." && $file != "..") {
                if (is_dir($source . "/" . $file)) {
                    if (!is_dir($dest . "/" . $file)) {
                        mkdir($dest . "/" . $file);
                    }
                    copy_recursive($source . "/" . $file, $dest . "/" . $file);
                } else {
                    copy($source . "/" . $file, $dest . "/" . $file);
                }
            }
        }
        closedir($dirHandle);
    } else {
        copy($source, $dest);
    }
}
Beispiel #9
0
         if (preg_match('/^([\\w]+)\\.php$/', $dirEntry, $regs)) {
             $pluginInfo[$regs[1]] = array('installUrl' => $packageurl, 'developer' => $developer, 'projectName' => $project_name, 'installDate' => time());
         }
         $bu_dir = time();
         if (file_exists($pluginDestination . '/' . $dirEntry)) {
             print ' ' . s('updating existing plugin');
             if (preg_match('/(.*)\\.php$/', $dirEntry, $regs)) {
                 $pluginsForUpgrade[] = $regs[1];
             }
             @rename($pluginDestination . '/' . $dirEntry, $pluginDestination . '/' . $dirEntry . '.' . $bu_dir);
         } else {
             print ' ' . s('new plugin');
         }
         #       var_dump($pluginInfo);
         print '<br/>';
         if (copy_recursive($GLOBALS['tmpdir'] . '/phpListPluginInstall/' . $dir_prefix . '/plugins/' . $dirEntry, $pluginDestination . '/' . $dirEntry)) {
             delFsTree($pluginDestination . '/' . $dirEntry . '.' . $bu_dir);
             $installOk = true;
         } elseif (is_dir($pluginDestination . '/' . $dirEntry . '.' . $bu_dir)) {
             ## try to place old one back
             @rename($pluginDestination . '/' . $dirEntry . '.' . $bu_dir, $pluginDestination . '/' . $dirEntry);
         }
     }
 }
 foreach ($pluginInfo as $plugin => $pluginDetails) {
     #  print 'Writing '.$pluginDestination.'/'.$plugin.'.info.txt<br/>';
     file_put_contents($pluginDestination . '/' . $plugin . '.info.txt', serialize($pluginDetails));
 }
 ## clean up
 delFsTree($GLOBALS['tmpdir'] . '/phpListPluginInstall');
 if ($installOk) {
function get_required_upgrades($soapclient, $session)
{
    global $sugar_config, $sugar_version;
    require_once 'vendor/nusoap//nusoap.php';
    $errors = array();
    $upgrade_history = new UpgradeHistory();
    $upgrade_history->disable_row_level_security = true;
    $installeds = $upgrade_history->getAllOrderBy('date_entered ASC');
    $history = array();
    require_once 'soap/SoapError.php';
    $error = new SoapError();
    foreach ($installeds as $installed) {
        $history[] = array('id' => $installed->id, 'filename' => $installed->filename, 'md5' => $installed->md5sum, 'type' => $installed->type, 'status' => $installed->status, 'version' => $installed->version, 'date_entered' => $installed->date_entered, 'error' => $error->get_soap_array());
    }
    $result = $soapclient->call('get_required_upgrades', array('session' => $session, 'client_upgrade_history' => $history, 'client_version' => $sugar_version));
    $tempdir_parent = create_cache_directory("disc_client");
    $temp_dir = tempnam($tempdir_parent, "sug");
    sugar_mkdir($temp_dir, 0775);
    $upgrade_installed = false;
    if (empty($soapclient->error_str) && $result['error']['number'] == 0) {
        foreach ($result['upgrade_history_list'] as $upgrade) {
            $file_result = $soapclient->call('get_encoded_file', array('session' => $session, 'filename' => $upgrade['filename']));
            if (empty($soapclient->error_str) && $result['error']['number'] == 0) {
                if ($file_result['md5'] == $upgrade['md5']) {
                    $newfile = write_encoded_file($file_result, $temp_dir);
                    unzip($newfile, $temp_dir);
                    global $unzip_dir;
                    $unzip_dir = $temp_dir;
                    if (file_exists("{$temp_dir}/manifest.php")) {
                        require_once "{$temp_dir}/manifest.php";
                        global $manifest_arr;
                        $manifest_arr = $manifest;
                        if (!isset($manifest['offline_client_applicable']) || $manifest['offline_client_applicable'] == true || $manifest['offline_client_applicable'] == 'true') {
                            if (file_exists("{$temp_dir}/scripts/pre_install.php")) {
                                require_once "{$temp_dir}/scripts/pre_install.php";
                                pre_install();
                            }
                            if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") {
                                $zip_from_dir = $manifest['copy_files']['from_dir'];
                            }
                            $source = "{$temp_dir}/{$zip_from_dir}";
                            $dest = getcwd();
                            copy_recursive($source, $dest);
                            if (file_exists("{$temp_dir}/scripts/post_install.php")) {
                                require_once "{$temp_dir}/scripts/post_install.php";
                                post_install();
                            }
                            //save newly installed upgrade
                            $new_upgrade = new UpgradeHistory();
                            $new_upgrade->filename = $upgrade['filename'];
                            $new_upgrade->md5sum = $upgrade['md5'];
                            $new_upgrade->type = $upgrade['type'];
                            $new_upgrade->version = $upgrade['version'];
                            $new_upgrade->status = "installed";
                            $new_upgrade->save();
                            $upgrade_installed = true;
                        }
                    }
                }
            }
        }
    }
    return $upgrade_installed;
}
Beispiel #11
0
function upgradeDCEFiles($argv, $instanceUpgradePath)
{
    //copy and update following files from upgrade package
    $upgradeTheseFiles = array('cron.php', 'download.php', 'index.php', 'install.php', 'soap.php', 'sugar_version.php', 'vcal_server.php');
    foreach ($upgradeTheseFiles as $file) {
        $srcFile = clean_path("{$instanceUpgradePath}/{$file}");
        $destFile = clean_path("{$argv[3]}/{$file}");
        if (file_exists($srcFile)) {
            if (!is_dir(dirname($destFile))) {
                mkdir_recursive(dirname($destFile));
                // make sure the directory exists
            }
            copy_recursive($srcFile, $destFile);
            $_GET['TEMPLATE_PATH'] = $destFile;
            $_GET['CONVERT_FILE_ONLY'] = true;
            if (!class_exists('TemplateConverter')) {
                include $argv[7] . 'templateConverter.php';
            } else {
                TemplateConverter::convertFile($_GET['TEMPLATE_PATH']);
            }
        }
    }
}
Beispiel #12
0
/**
 * Recursively copy files
 * @param string $path file path with no trailing slash
 * @return void
 */
function copy_recursive($path)
{
    $path .= '/';
    if (!is_readable('site/' . $path)) {
        mkdir('site/' . $path, 0755, true);
    }
    foreach (scandir($path) as $file) {
        if (in_array($file, array('.', '..'), true)) {
            continue;
        } elseif (is_dir($path . $file)) {
            copy_recursive($path . $file);
        } else {
            copy($path . $file, 'site/' . $path . $file);
        }
    }
}
 function exportProject($package, $export = true, $clean = true)
 {
     $tmppath = "custom/modulebuilder/projectTMP/";
     if (file_exists($this->getPackageDir())) {
         if (mkdir_recursive($tmppath)) {
             copy_recursive($this->getPackageDir(), $tmppath . "/" . $this->name);
             $manifest = $this->getManifest(true, $export) . $this->exportProjectInstall($package, $export);
             $fp = sugar_fopen($tmppath . '/manifest.php', 'w');
             fwrite($fp, $manifest);
             fclose($fp);
             if (file_exists('modules/ModuleBuilder/MB/LICENSE.txt')) {
                 copy('modules/ModuleBuilder/MB/LICENSE.txt', $tmppath . '/LICENSE.txt');
             } else {
                 if (file_exists('LICENSE.txt')) {
                     copy('LICENSE.txt', $tmppath . '/LICENSE.txt');
                 }
             }
             $readme_contents = $this->readme;
             $readmefp = sugar_fopen($tmppath . '/README.txt', 'w');
             fwrite($readmefp, $readme_contents);
             fclose($readmefp);
         }
     }
     require_once 'include/utils/zip_utils.php';
     $date = date('Y_m_d_His');
     $zipDir = "custom/modulebuilder/packages/ExportProjectZips";
     if (!file_exists($zipDir)) {
         mkdir_recursive($zipDir);
     }
     $cwd = getcwd();
     chdir($tmppath);
     zip_dir('.', $cwd . '/' . $zipDir . '/project_' . $this->name . $date . '.zip');
     chdir($cwd);
     if ($clean && file_exists($tmppath)) {
         rmdir_recursive($tmppath);
     }
     if ($export) {
         header('Location:' . $zipDir . '/project_' . $this->name . $date . '.zip');
     }
     return $zipDir . '/project_' . $this->name . $date . '.zip';
 }
Beispiel #14
0
/**
 * change from using the older SugarCache in 6.1 and below to the new one in 6.2
 */
function upgradeSugarCache($file)
{
    global $sugar_config;
    // file = getcwd().'/'.$sugar_config['upload_dir'].$_FILES['upgrade_zip']['name'];
    $cacheUploadUpgradesTemp = clean_path(mk_temp_dir("{$sugar_config['upload_dir']}upgrades/temp"));
    unzip($file, $cacheUploadUpgradesTemp);
    if (!file_exists(clean_path("{$cacheUploadUpgradesTemp}/manifest.php"))) {
        logThis("*** ERROR: no manifest file detected while bootstraping upgrade wizard files!");
        return;
    } else {
        include clean_path("{$cacheUploadUpgradesTemp}/manifest.php");
    }
    $allFiles = array();
    if (file_exists(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/database"))) {
        $allFiles = findAllFiles(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/database"), $allFiles);
    }
    if (file_exists(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/SugarCache"))) {
        $allFiles = findAllFiles(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/SugarCache"), $allFiles);
    }
    if (file_exists(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/utils/external_cache.php"))) {
        $allFiles[] = clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/utils/external_cache.php");
    }
    $cwd = clean_path(getcwd());
    foreach ($allFiles as $k => $file) {
        $file = clean_path($file);
        $destFile = str_replace(clean_path($cacheUploadUpgradesTemp . '/' . $manifest['copy_files']['from_dir']), $cwd, $file);
        if (!is_dir(dirname($destFile))) {
            mkdir_recursive(dirname($destFile));
            // make sure the directory exists
        }
        if (stristr($file, 'uw_main.tpl')) {
            logThis('Skipping "' . $file . '" - file copy will during commit step.');
        } else {
            logThis('updating UpgradeWizard code: ' . $destFile);
            copy_recursive($file, $destFile);
        }
    }
    logThis('is sugar_file_util there ' . file_exists(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/utils/sugar_file_utils.php")));
    if (file_exists(clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/utils/sugar_file_utils.php"))) {
        $file = clean_path("{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}/include/utils/sugar_file_utils.php");
        $destFile = str_replace(clean_path($cacheUploadUpgradesTemp . '/' . $manifest['copy_files']['from_dir']), $cwd, $file);
        copy($file, $destFile);
    }
}
Beispiel #15
0
function clean_copy_assets($path)
{
    @mkdir($path);
    $options = $GLOBALS["options"];
    //Clean
    clean_directory($path);
    //Copy assets
    $unnecessaryImgs = array('./img/favicon.png', './img/favicon-blue.png', './img/favicon-green.png', './img/favicon-navy.png', './img/favicon-red.png');
    $unnecessaryJs = array();
    if ($options['colors']) {
        $unnecessaryLess = array('./less/daux-blue.less', './less/daux-green.less', './less/daux-navy.less', './less/daux-red.less');
        copy_recursive('./less', $path . '/', $unnecessaryLess);
        $unnecessaryImgs = array_diff($unnecessaryImgs, array('./img/favicon.png'));
    } else {
        $unnecessaryJs = array('./js/less.min.js');
        @mkdir($path . '/css');
        @copy('./css/daux-' . $options['theme'] . '.min.css', $path . '/css/daux-' . $options['theme'] . '.min.css');
        $unnecessaryImgs = array_diff($unnecessaryImgs, array('./img/favicon-' . $options['theme'] . '.png'));
    }
    copy_recursive('./img', $path . '/', $unnecessaryImgs);
    copy_recursive('./js', $path . '/', $unnecessaryJs);
}
Beispiel #16
0
 function build($path)
 {
     if (file_exists($this->path . '/language/')) {
         copy_recursive($this->path . '/language/', $path . '/language/');
     }
 }
 if (!$ret) {
     $errorstring = "Error creating export directory\n<br>\n" . "Name: " . $dir . "\n<br>\n" . "\n<br>\n";
     die($errorstring);
 }
 // do we need to copy the viewer skeleton?
 if ($withviewer) {
     $viewerdir = '';
     if ($targetsystem == 'mac') {
         $viewerdir = $dilpsdir . 'viewer' . DIRECTORY_SEPARATOR . 'mac' . DIRECTORY_SEPARATOR;
     } else {
         $viewerdir = $dilpsdir . 'viewer' . DIRECTORY_SEPARATOR . 'windows' . DIRECTORY_SEPARATOR;
     }
     // copy viewer with PHP-functions
     $olddir = getcwd();
     chdir($viewerdir);
     $ret = copy_recursive('.', $exportdirlong . $user['login'] . DIRECTORY_SEPARATOR . $date . DIRECTORY_SEPARATOR);
     if (!$ret) {
         echo "Error copying viewer skeleton for current export\n<br>\n";
         echo "\n<br>\n";
         exit;
     }
     chdir($olddir);
 }
 // start reading actual data
 // $db->debug = true;
 $sql = "SELECT DISTINCT * FROM " . $db_prefix . "img, " . $db_prefix . "img_group, " . $db_prefix . "meta" . " WHERE " . $db_prefix . "img.collectionid = " . $db_prefix . "meta.collectionid" . " AND " . $db_prefix . "img.imageid = " . $db_prefix . "meta.imageid" . " AND " . $db_prefix . "img.collectionid = " . $db_prefix . "img_group.collectionid" . " AND " . $db_prefix . "img.imageid = " . $db_prefix . "img_group.imageid" . get_groupid_where_clause($groupid, $db, $db_prefix, $subgroups);
 $rs = $db->Execute($sql);
 // die ($sql);
 while (!$rs->EOF) {
     // print_r($rs->fields);
     $xmlout = "<?" . "xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n";
Beispiel #18
0
 function copy_path($from, $to, $backup_path = '', $uninstall = false)
 {
     //function copy_path($from, $to){
     /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
     $to = str_replace('<basepath>', $this->base_dir, $to);
     if (!$uninstall) {
         $from = str_replace('<basepath>', $this->base_dir, $from);
         $GLOBALS['log']->debug('Copy ' . $from);
     } else {
         $from = str_replace('<basepath>', $backup_path, $from);
         //$GLOBALS['log']->debug('Restore ' . $from);
     }
     $from = clean_path($from);
     $to = clean_path($to);
     $dir = dirname($to);
     //there are cases where if we need to create a directory in the root directory
     if ($dir == '.' && is_dir($from)) {
         $dir = $to;
     }
     if (!sugar_is_dir($dir, 'instance')) {
         mkdir_recursive($dir, true);
     }
     /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
     if (empty($backup_path)) {
         /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
         if (!copy_recursive($from, $to)) {
             die('Failed to copy ' . $from . ' ' . $to);
         }
         /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
     } elseif (!$this->copy_recursive_with_backup($from, $to, $backup_path, $uninstall)) {
         die('Failed to copy ' . $from . ' to ' . $to);
     }
     /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
 }
Beispiel #19
0
 function copy($new_name)
 {
     $old = $this->getModuleDir();
     $count = 0;
     $old_name = $this->key_name;
     $this->name = $new_name;
     $this->key_name = $this->package_key . '_' . $this->name;
     $new = $this->getModuleDir();
     while (file_exists($new)) {
         $count++;
         $this->name = $new_name . $count;
         $this->key_name = $this->package_key . '_' . $this->name;
         $new = $this->getModuleDir();
     }
     $new = $this->getModuleDir();
     $copied = copy_recursive($old, $new);
     if ($copied) {
         $this->renameMetaData($new, $old_name);
         $this->renameLanguageFiles($new, true);
     }
     return $copied;
 }
Beispiel #20
0
/**
 * Copy a file, or recursively copy a folder and its contents
 * @param       string   $source    Source path
 * @param       string   $dest      Destination path
 * @param       string   $permissions New folder creation permissions
 * @return      bool     Returns TRUE on success, FALSE on failure
 */
function ac_dir_copy($source, $dest, $permissions = 0775)
{
    // Check for symlinks
    if (is_link($source)) {
        return symlink(readlink($source), $dest);
    }
    // Simple copy for a file
    if (is_file($source)) {
        return copy($source, $dest);
    }
    // Make destination directory
    if (!is_dir($dest)) {
        mkdir($dest, $permissions);
    }
    // Loop through the folder
    $dir = dir($source);
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        // Deep copy directories
        copy_recursive("{$source}/{$entry}", "{$dest}/{$entry}");
    }
    // Clean up
    $dir->close();
    return true;
}
Beispiel #21
0
/**
 *	recursive copy function for php
 *
 *	recursive copy function for php with some error checking
 *
 *	@access		public
 *	@param 		string $dirsource
 *	@param 		string $dirdest
 *	@return		bool
 *
 */
function copy_recursive($dirsource, $dirdest)
{
    if (is_dir($dirsource)) {
        $dir_handle = opendir($dirsource);
    } else {
        echo "copy_recursive error: source cannot be opened\n<br>\n";
        return false;
    }
    if (!is_dir($dirdest)) {
        echo "copy_recursive error: destination is not a directory\n<br>\n";
        return false;
    } else {
        if (!is_dir($dirdest . '/' . $dirsource)) {
            mkdir($dirdest . '/' . $dirsource, 0755);
        }
        while ($file = readdir($dir_handle)) {
            if ($file != "." && $file != "..") {
                if (!is_dir($dirsource . '/' . $file)) {
                    copy($dirsource . '/' . $file, $dirdest . '/' . $dirsource . '/' . $file);
                } else {
                    copy_recursive($dirsource . '/' . $file, $dirdest);
                }
            }
        }
        closedir($dir_handle);
        return true;
    }
}
function smarty_function_group_export($params, &$smarty)
{
    global $db, $db_prefix;
    global $exportdir, $exportdirlong;
    global $user;
    global $zip_binary;
    // print_r($params);
    // $db->debug = true;
    // check parameters
    if (empty($params['id'])) {
        $smarty->trigger_error("assign: missing 'id' parameter");
        return;
    } else {
        $id = $params['id'];
    }
    if (empty($params['name'])) {
        $smarty->trigger_error("assign: missing 'name' parameter");
        return;
    } else {
        $name = $params['name'];
    }
    if (empty($params['subgroups'])) {
        $smarty->trigger_error("assign: missing 'subgroups' parameter");
        return;
    } else {
        if ($params['subgroups'] == 'yes') {
            $subgroups = true;
        } else {
            $subgroups = false;
        }
    }
    if (empty($params['withviewer'])) {
        $smarty->trigger_error("assign: missing 'withviewer' parameter");
        return;
    } else {
        if ($params['withviewer'] == 'yes') {
            $withviewer = true;
        } else {
            $withviewer = false;
        }
    }
    if (empty($params['targetsystem'])) {
        $smarty->trigger_error("assign: missing 'targetsystem' parameter");
        return;
    } else {
        $targetsystem = $params['targetsystem'];
    }
    if (!empty($params['comment'])) {
        $comment = $params['comment'];
    } else {
        $comment = '';
    }
    if (empty($params['result'])) {
        $smarty->trigger_error("assign: missing 'result' parameter");
        return;
    }
    // generate unique filename for this export
    $tmpid = generate_random_string();
    while (file_exists($exportdir . DIRECTORY_SEPARATOR . $user['login'] . DIRECTORY_SEPARATOR . $tmpid . '.zip') || file_exists($exportdir . DIRECTORY_SEPARATOR . $user['login'] . DIRECTORY_SEPARATOR . $tmpid)) {
        $tmpid = generate_random_string();
    }
    // check if export sub-directories already exists and are writeable
    $create_directories = array($user['login'], $user['login'] . DIRECTORY_SEPARATOR . $tmpid, $user['login'] . DIRECTORY_SEPARATOR . $tmpid . DIRECTORY_SEPARATOR . 'xml', $user['login'] . DIRECTORY_SEPARATOR . $tmpid . DIRECTORY_SEPARATOR . 'images', $user['login'] . DIRECTORY_SEPARATOR . $tmpid . DIRECTORY_SEPARATOR . 'thumbnails');
    $ret = true;
    foreach ($create_directories as $dir) {
        $sret = check_dir($exportdir . DIRECTORY_SEPARATOR . $dir, true, true, 0755);
        $ret = $ret & $sret;
    }
    if (!$ret) {
        $result = 'E_CREATE_DIRECTORY';
    } else {
        // if we succeeded in creating the directories, this is our temporary directory
        $tmpdir = $exportdir . $user['login'] . DIRECTORY_SEPARATOR . $tmpid;
        $tmpdirlong = $exportdirlong . $user['login'] . DIRECTORY_SEPARATOR . $tmpid;
        // do we need to copy the viewer skeleton?
        if ($withviewer) {
            $viewerdir = '';
            if ($targetsystem == 'mac') {
                $viewerdir = $dilpsdir . 'viewer' . DIRECTORY_SEPARATOR . 'mac' . DIRECTORY_SEPARATOR;
            } else {
                $viewerdir = $dilpsdir . 'viewer' . DIRECTORY_SEPARATOR . 'windows' . DIRECTORY_SEPARATOR;
            }
            // copy viewer with PHP-functions
            $olddir = getcwd();
            chdir($viewerdir);
            $ret = copy_recursive('.', $tmpdirlong . DIRECTORY_SEPARATOR);
            chdir($olddir);
        }
        if (!$ret) {
            $result = 'E_COPY_VIEWER';
        } else {
            // start reading actual data
            $sql = "SELECT DISTINCT * FROM " . $db_prefix . "img, " . $db_prefix . "img_group, " . $db_prefix . "meta" . " WHERE " . $db_prefix . "img.collectionid = " . $db_prefix . "meta.collectionid" . " AND " . $db_prefix . "img.imageid = " . $db_prefix . "meta.imageid" . " AND " . $db_prefix . "img.collectionid = " . $db_prefix . "img_group.collectionid" . " AND " . $db_prefix . "img.imageid = " . $db_prefix . "img_group.imageid" . get_groupid_where($id, $db, $db_prefix, $subgroups);
            $rs = $db->Execute($sql);
            $xml_ret = true;
            $img_ret = true;
            // we continue, even when there are errors
            while (!$rs->EOF) {
                // print_r($rs->fields);
                $xmlout = "<?" . "xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n";
                $xmlout .= "<imgdata>\n";
                $xmlout .= "<width>" . utf8_encode($rs->fields['width']) . "</width>\n";
                $xmlout .= "<height>" . utf8_encode($rs->fields['height']) . "</height>\n";
                $xmlout .= "<name>" . utf8_encode($rs->fields['name1']) . "</name>\n";
                $xmlout .= "<vorname>" . utf8_encode($rs->fields['name2']) . "</vorname>\n";
                $xmlout .= "<titel>" . utf8_encode($rs->fields['title']) . "</titel>\n";
                $xmlout .= "<datierung>" . utf8_encode($rs->fields['dating']) . "</datierung>\n";
                $xmlout .= "<material>" . utf8_encode($rs->fields['material']) . "</material>\n";
                $xmlout .= "<technik>" . utf8_encode($rs->fields['technique']) . "</technik>\n";
                $xmlout .= "<format>" . utf8_encode($rs->fields['format']) . "</format>\n";
                $xmlout .= "<stadt>" . utf8_encode($rs->fields['location']) . "</stadt>\n";
                $xmlout .= "<institution>" . utf8_encode($rs->fields['institution']) . "</institution>\n";
                $xmlout .= "<literatur>" . utf8_encode($rs->fields['literature']) . "</literatur>\n";
                $xmlout .= "<url>" . utf8_encode("images" . DIRECTORY_SEPARATOR . $rs->fields['filename']) . "</url>\n";
                $xmlout .= "<thumbnail>" . utf8_encode("thumbnail" . DIRECTORY_SEPARATOR . $rs->fields['filename']) . "</thumbnail>\n";
                $xmlout .= "<schlagworte>" . utf8_encode($rs->fields['keyword']) . "</schlagworte>\n";
                $xmlout .= "<quelle>" . utf8_encode($rs->fields['imagerights']) . "</quelle>\n";
                $xmlout .= "<comment>" . utf8_encode($rs->fields['commentary']) . "</comment>\n";
                $xmlout .= "</imgdata>\n";
                // print_r($xmlout);
                $sql2 = "SELECT base FROM " . $db_prefix . "img_base WHERE " . $db_prefix . "img_base.img_baseid = " . $db->qstr($rs->fields['img_baseid']);
                $path = $db->GetOne($sql2);
                $copyfilename = $rs->fields['collectionid'] . "-" . $rs->fields['imageid'] . ".jpg";
                $source = $path . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . '1600x1200' . DIRECTORY_SEPARATOR . $copyfilename;
                $dest = $tmpdir . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $copyfilename;
                $img_sret = @copy($source, $dest);
                /*
                echo ("Source: ".$source."\n<br>\n");
                echo ("Dest: ".$dest."\n<br>\n");
                */
                $source = $path . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . '120x90' . DIRECTORY_SEPARATOR . $copyfilename;
                $dest = $tmpdir . DIRECTORY_SEPARATOR . 'thumbnails' . DIRECTORY_SEPARATOR . $copyfilename;
                $thumb_sret = @copy($source, $dest);
                $handle = @fopen($tmpdir . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . $rs->fields['collectionid'] . '-' . $rs->fields['imageid'] . '.xml', 'w');
                if (!$handle) {
                    $xml_sret = false;
                } else {
                    $xml_sret = @fwrite($handle, $xmlout);
                }
                // cleanup
                fclose($handle);
                unset($xmlout);
                flush();
                $img_ret = $img_sret & $thumb_sret & $img_ret;
                $xml_ret = $xml_ret & $xml_sret;
                $rs->MoveNext();
            }
            // create zip archive
            $old = getcwd();
            chdir($exportdirlong . $user['login']);
            $cmd = $zip_binary . ' -9 -r -m  ' . escapeshellarg($tmpid . '.zip') . ' ' . escapeshellarg($tmpid);
            exec($cmd, $result, $ret);
            /*
            echo ("CMD: {$cmd}\n<br>\n");
            echo ("Result:");
            nl2br(print_r($result));
            echo ("\n<br>\n");
            echo ("Ret: {$ret} \n<br>\n");
            */
            if ($ret != 0) {
                $result = 'E_CREATE_ZIP';
            } else {
                chdir($olddir);
                $ret = @chmod($tmpdirlong . '.zip', 0755);
                // echo ("Ret: {$ret} \n<br>\n");
                if (!$ret) {
                    $result = 'E_CREATE_ZIP';
                } else {
                    if (insert_export($user['login'], $name, $tmpid . '.zip', $comment)) {
                        $result = 'R_EXPORT_SUCCESSFUL';
                    } else {
                        $result = 'E_ACCESS_DB';
                    }
                }
            }
        }
    }
    // if something went wrong, clean up a little bit
    if (file_exists($tmpdirlong)) {
        @delete_recursive($tmpdirlong);
    }
    $smarty->assign($params['result'], $result);
    if (!empty($params['sql'])) {
        $smarty->assign($params['sql'], $sql);
    }
}
Beispiel #23
0
function fileCopy($file_path)
{
    if (file_exists(clean_path($_SESSION['unzip_dir'] . '/' . $_SESSION['zip_from_dir'] . '/' . $file_path))) {
        $file = clean_path($_SESSION['unzip_dir'] . '/' . $_SESSION['zip_from_dir'] . '/' . $file_path);
        $destFile = str_replace(clean_path($_SESSION['unzip_dir'] . '/' . $_SESSION['zip_from_dir']), clean_path(getcwd()), $file);
        if (!is_dir(dirname($destFile))) {
            mkdir_recursive(dirname($destFile));
            // make sure the directory exists
        }
        copy_recursive($file, $destFile);
    }
}
Beispiel #24
0
<?php

require_once __DIR__ . '/settings.php';
require_once MLADEK_DIR . '/utils/filesystem.php';
switch ($argv[1]) {
    case 'startapp':
        copy_recursive(MLADEK_DIR . '/bin/myproject/myapp', $argv[2]);
        break;
    default:
        print "Unknown command '{$argv[1]}'\n";
        print "For creating new application run: php manage.php startapp <myapp>\n";
}
Beispiel #25
0
/**
 * change from using the older SugarCache in 6.1 and below to the new one in 6.2
 */
function upgradeSugarCache($file)
{
    global $sugar_config;
    $cacheUploadUpgradesTemp = mk_temp_dir(sugar_cached('upgrades/temp'));
    unzip($file, $cacheUploadUpgradesTemp);
    if (!file_exists(clean_path("{$cacheUploadUpgradesTemp}/manifest.php"))) {
        logThis("*** ERROR: no manifest file detected while bootstraping upgrade wizard files!");
        return;
    } else {
        include clean_path("{$cacheUploadUpgradesTemp}/manifest.php");
    }
    $from_dir = "{$cacheUploadUpgradesTemp}/{$manifest['copy_files']['from_dir']}";
    $allFiles = array();
    if (file_exists("{$from_dir}/include/SugarCache")) {
        $allFiles = findAllFiles("{$from_dir}/include/SugarCache", $allFiles);
    }
    if (file_exists("{$from_dir}/include/database")) {
        $allFiles = findAllFiles("{$from_dir}/include/database", $allFiles);
    }
    if (file_exists("{$from_dir}/include/utils/external_cache.php")) {
        $allFiles[] = "{$from_dir}/include/utils/external_cache.php";
    }
    if (file_exists("{$from_dir}/include/utils/sugar_file_utils.php")) {
        $allFiles[] = "{$from_dir}/include/utils/sugar_file_utils.php";
    }
    if (file_exists("{$from_dir}/include/utils/sugar_file_utils.php")) {
        $allFiles[] = "{$from_dir}/include/utils/sugar_file_utils.php";
    }
    foreach ($allFiles as $k => $file) {
        $destFile = str_replace($from_dir . "/", "", $file);
        if (!is_dir(dirname($destFile))) {
            mkdir_recursive(dirname($destFile));
            // make sure the directory exists
        }
        if (stristr($file, 'uw_main.tpl')) {
            logThis('Skipping "' . $file . '" - file copy will during commit step.');
        } else {
            logThis('updating UpgradeWizard code: ' . $destFile);
            copy_recursive($file, $destFile);
        }
    }
}
Beispiel #26
0
<?php

require_once __DIR__ . '/../utils/filesystem.php';
$argv = $_SERVER['argv'];
switch ($argv[1]) {
    case 'startproject':
        copy_recursive(__DIR__ . '/myproject', $argv[2], array('.svn'));
        $settings = preg_replace("/define\\('MLADEK_DIR', '.*'\\)/", "define('MLADEK_DIR', '" . str_replace('\\', '/', realpath(__DIR__ . '/../')) . "')", file_get_contents(__DIR__ . '/myproject/settings.php'));
        file_put_contents($argv[2] . '/settings.php', $settings);
        print "Please set 'RewriteBase' in your {$argv['2']}/www/.htaccess file.\n";
        print "Please set 'REWRITEBASE' in your {$argv['2']}/www/settings.php file to same value without end slash.\n";
        break;
    default:
        print "Unknown command '{$argv[1]}'\n";
        print "For creating new project run: php <path_to_mladek>/mladek/bin/mladek-admin.php startproject <myproject>\n";
}
Beispiel #27
0
function commitPatch($unlink = false, $type = 'patch')
{
    require_once 'ModuleInstall/ModuleInstaller.php';
    require_once 'include/entryPoint.php';
    global $mod_strings;
    global $base_upgrade_dir;
    global $base_tmp_upgrade_dir;
    global $db;
    $GLOBALS['db'] = $db;
    $errors = array();
    $files = array();
    global $current_user;
    $current_user = new User();
    $current_user->is_admin = '1';
    $old_mod_strings = $mod_strings;
    if (is_dir($base_upgrade_dir)) {
        $files = findAllFiles("{$base_upgrade_dir}/{$type}", $files);
        $mi = new ModuleInstaller();
        $mi->silent = true;
        $mod_strings = return_module_language('en', "Administration");
        foreach ($files as $file) {
            if (!preg_match('#.*\\.zip\\$#', $file)) {
                continue;
            }
            // handle manifest.php
            $target_manifest = remove_file_extension($file) . '-manifest.php';
            include $target_manifest;
            $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir);
            unzip($file, $unzip_dir);
            if (file_exists("{$unzip_dir}/scripts/pre_install.php")) {
                require_once "{$unzip_dir}/scripts/pre_install.php";
                pre_install();
            }
            if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") {
                $zip_from_dir = $manifest['copy_files']['from_dir'];
            }
            $source = "{$unzip_dir}/{$zip_from_dir}";
            $dest = getcwd();
            copy_recursive($source, $dest);
            if (file_exists("{$unzip_dir}/scripts/post_install.php")) {
                require_once "{$unzip_dir}/scripts/post_install.php";
                post_install();
            }
            $new_upgrade = new UpgradeHistory();
            $new_upgrade->filename = $file;
            $new_upgrade->md5sum = md5_file($file);
            $new_upgrade->type = $manifest['type'];
            $new_upgrade->version = $manifest['version'];
            $new_upgrade->status = "installed";
            //$new_upgrade->author        = $manifest['author'];
            $new_upgrade->name = $manifest['name'];
            $new_upgrade->description = $manifest['description'];
            $serial_manifest = array();
            $serial_manifest['manifest'] = isset($manifest) ? $manifest : '';
            $serial_manifest['installdefs'] = isset($installdefs) ? $installdefs : '';
            $serial_manifest['upgrade_manifest'] = isset($upgrade_manifest) ? $upgrade_manifest : '';
            $new_upgrade->manifest = base64_encode(serialize($serial_manifest));
            $new_upgrade->save();
            unlink($file);
        }
        //rof
    }
    //fi
    $mod_strings = $old_mod_strings;
}
 function copy_path($from, $to, $backup_path = '', $uninstall = false)
 {
     //function copy_path($from, $to){
     /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
     $to = str_replace('<basepath>', $this->base_dir, $to);
     if (!$uninstall) {
         $from = str_replace('<basepath>', $this->base_dir, $from);
         $GLOBALS['log']->debug('Copy ' . $from);
     } else {
         $from = str_replace('<basepath>', $backup_path, $from);
         //$GLOBALS['log']->debug('Restore ' . $from);
     }
     $from = clean_path($from);
     $to = clean_path($to);
     $dir = dirname($to);
     if (!file_exists($dir)) {
         mkdir_recursive($dir, true);
     }
     /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
     if (empty($backup_path)) {
         /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
         if (!copy_recursive($from, $to)) {
             die('Failed to copy ' . $from . ' ' . $to);
         }
         /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
     } elseif (!$this->copy_recursive_with_backup($from, $to, $backup_path, $uninstall)) {
         die('Failed to copy ' . $from . ' ' . $to);
     }
     /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */
 }