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 remove($themeName)
 {
     $themeDir = FilesHelper::normalizePath(getThemeDir($themeName));
     if (!is_dir($themeDir)) {
         return array('errors' => 'Theme `' . $themeName . '` does not exist');
     }
     if (Designer::isActiveTheme($themeName)) {
         return array('errors' => 'Theme `' . $themeName . '` is active');
     }
     ProviderLog::start('removeTheme');
     $helper = new ThemeInstallHelper();
     $previewName = $themeName . _PREVIEW_SUFFIX_;
     $dirs = array($themeName => $themeDir, $previewName => FilesHelper::normalizePath(getThemeDir($previewName)));
     foreach ($dirs as $name => $dir) {
         if ($helper->isThemeInstalled($name)) {
             Designer::deleteTheme($name);
         }
         if (is_dir($dir)) {
             FilesHelper::removeDir($dir);
         }
     }
     ProviderLog::end('removeTheme');
     return array('result' => 'done', 'log' => ProviderLog::getLog());
 }