function uploadTheme($themeName, $filename, $tmp_path)
{
    $uniqid = uniqid();
    $sandbox = FilesHelper::normalizePath(_PS_CACHE_DIR_ . 'sandbox' . DIRECTORY_SEPARATOR . $uniqid) . '/';
    $uploadDir = $sandbox . ThemeInstallHelper::UPLOADED_THEME_DIR_NAME;
    // used in AdminThemesController
    $base_path = $uploadDir . '.zip';
    FilesHelper::createDir($sandbox);
    FilesHelper::renameFile($tmp_path, $base_path);
    $archive = new PclZip($base_path);
    deleteFromArchive($archive, 'modules', true);
    // We upload new theme, not modules to save module functionality
    $helper = new ThemeInstallHelper();
    if ($helper->install($base_path, $sandbox)) {
        $result = array('status' => 'done', 'path' => $base_path);
    } else {
        $themesDir = $uploadDir . '/themes';
        $files = FilesHelper::enumerate($themesDir, false);
        // not enumerateFiles method with directory checking
        if (count($files) === 1 && is_dir($files[0]['path'])) {
            $themeName = str_replace("{$themesDir}/", '', $files[0]['path']);
        }
        if ($themeName && ($theme = Theme::getByDirectory($themeName)) && is_file($uploadDir . '/Config.xml')) {
            $themeDir = $themesDir . '/' . $themeName;
            $previewThemeDir = $themeDir . '/' . $themeName . _PREVIEW_SUFFIX_;
            $newThemeName = checkThemeName($themeName);
            $newThemeDir = $themesDir . '/' . $newThemeName;
            $newThemePreviewDir = $themeDir . '/' . $newThemeName . _PREVIEW_SUFFIX_;
            // 1. rename inner preview folder
            processRename($themeDir, $previewThemeDir, $newThemeDir, $newThemePreviewDir, $newThemeName);
            $newThemePreviewDir = $newThemeDir . '/' . $newThemeName . _PREVIEW_SUFFIX_;
            // 2. now preview folder is correct
            FilesHelper::deleteFile($uploadDir . '/Config.xml');
            FilesHelper::copyFile($newThemePreviewDir . '/designer/Export/Config.xml', $uploadDir . '/Config.xml');
            unset($archive);
            FilesHelper::deleteFile($base_path);
            $archive = new PclZip($base_path);
            addToArchive($archive, $uploadDir, $uploadDir);
            $helper = new ThemeInstallHelper();
            // new object with no errors
            if ($helper->install($base_path, $sandbox)) {
                $result = array('status' => 'done', 'path' => $base_path);
            } else {
                $result = array('status' => 'error', 'errors' => Tools::jsonEncode($helper->getErrors()));
            }
        } else {
            $result = array('status' => 'error', 'errors' => 'Please make sure, that you have selected a valid PrestaShop theme.');
        }
    }
    return $result;
}
 public function copy($newThemeName = '')
 {
     if (!is_dir($this->_themeDir)) {
         return array('errors' => 'Theme `' . $this->_themeName . '` doesn\'t exist');
     }
     ProviderLog::start('copyTheme');
     $newThemeName = $newThemeName ? checkThemeName($newThemeName) : checkThemeName($this->_themeName);
     $this->prepareCopyRename($newThemeName, false);
     save_config($this->_previewThemeDir, $this->_previewThemeDir, $this->_themeName);
     // HACK: We have to rename source Config.xml back
     Designer::addTheme($newThemeName);
     ProviderLog::end('copyTheme');
     return array('result' => 'done', 'log' => ProviderLog::getLog(), 'newName' => $newThemeName);
 }