Skip to content

Instantly share code, notes, and snippets.

@agiannis
Last active June 26, 2020 15:28
Show Gist options
  • Save agiannis/f419758485fe798b7debc3a8e8d0fd19 to your computer and use it in GitHub Desktop.
Save agiannis/f419758485fe798b7debc3a8e8d0fd19 to your computer and use it in GitHub Desktop.
labels : cs-cart , tools , php , plugin , addon , extract
find . -type f -path *plugin_name* | grep -v ".history/" | zip plugin_name.zip -@
<?php
/**
* Extracts a cs-cart plugin. This should be placed on the root directory of cs-cart
* @param $plugin_name the directory name of the plugin
*/
function extract_plugin($plugin_name)
{
if (empty($plugin_name)) {
return;
}
$path = __DIR__ . '/';
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
$filtered = new RegexIterator($files, '/.*' . $plugin_name . '.*/');
$zip = new ZipArchive();
$filename = "./$plugin_name.zip";
if ($zip->open($filename, ZipArchive::CREATE) !== TRUE) {
exit("cannot open <$filename>\n");
}
foreach ($filtered as $file) {
if (is_file($file->getPathname())) {
$zip->addFile($file->getPathname(), str_replace($path, '', $file->getPathname()));
}
}
$zip->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment