예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $httpClient = $this->getHttpClientHelper();
     $site_name = $input->getArgument('site-name');
     $version = $input->getArgument('version');
     if ($version) {
         $release_selected = $version;
     } else {
         // Getting Module page header and parse to get module Node
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.getting-releases')) . '</info>');
         // Page for Drupal releases filter by Drupal 8
         $project_release_d8 = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234';
         // Parse release module page to get Drupal 8 releases
         try {
             $html = $httpClient->getHtml($project_release_d8);
         } catch (\Exception $e) {
             $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
             return;
         }
         $crawler = new Crawler($html);
         $releases = [];
         foreach ($crawler->filter('span.file a') as $element) {
             if (strpos($element->nodeValue, ".tar.gz") > 0) {
                 $release_name = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue));
                 $releases[$release_name] = $element->nodeValue;
             }
         }
         if (empty($releases)) {
             $output->writeln('[+] <error>' . $this->trans('commands.module.site.new.no-releases') . '</error>');
             return;
         }
         // List module releases to enable user to select his favorite release
         $questionHelper = $this->getQuestionHelper();
         $question = new ChoiceQuestion('Please select your favorite release', array_combine(array_keys($releases), array_keys($releases)), 0);
         $release_selected = $questionHelper->ask($input, $output, $question);
     }
     $release_file_path = 'http://ftp.drupal.org/files/projects/drupal-' . $release_selected . '.tar.gz';
     // Destination file to download the release
     $destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz";
     try {
         // Start the process to download the zip file of release and copy in contrib folter
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloading'), $release_selected) . '</info>');
         $httpClient->downloadFile($release_file_path, $destination);
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.extracting'), $release_selected) . '</info>');
         $zippy = Zippy::load();
         $archive = $zippy->open($destination);
         $archive->extract('./');
         try {
             $fs = new Filesystem();
             $fs->rename('./drupal-' . $release_selected, './' . $site_name);
         } catch (IOExceptionInterface $e) {
             $output->writeln('[+] <error>' . sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()) . '</error>');
         }
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloaded'), $release_selected, $site_name) . '</info>');
     } catch (\Exception $e) {
         $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
         return;
     }
     return true;
 }
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  * @param $project
  * @param $version
  * @param $type
  * @return string
  */
 public function downloadProject(DrupalStyle $io, $project, $version, $type)
 {
     $commandKey = str_replace(':', '.', $this->getName());
     $io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.downloading'), $project, $version));
     try {
         $destination = $this->getDrupalApi()->downloadProjectRelease($project, $version);
         $drupal = $this->getDrupalHelper();
         $projectPath = sprintf('%s/%s', $drupal->isValidInstance() ? $drupal->getRoot() : getcwd(), $this->getExtractPath($type));
         if (!file_exists($projectPath)) {
             if (!mkdir($projectPath, 0777, true)) {
                 $io->error($this->trans('commands.' . $commandKey . '.messages.error-creating-folder') . ': ' . $projectPath);
                 return null;
             }
         }
         $zippy = Zippy::load();
         $archive = $zippy->open($destination);
         $archive->extract($projectPath);
         unlink($destination);
         if ($type != 'core') {
             $io->success(sprintf($this->trans('commands.' . $commandKey . '.messages.downloaded'), $project, $version, sprintf('%s/%s', $projectPath, $project)));
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return null;
     }
     return $projectPath;
 }
예제 #3
0
 /**
  * Fetch a package from GitHub
  * @param  {String}    the command option to provide the rule for
  * @param  {String}    the path to the package to be downloaded
  *
  * @return {String}    the modified file contents
  */
 public function fetchStarterKit($starterkit = "")
 {
     // double-checks options was properly set
     if (empty($starterkit)) {
         Console::writeError("please provide a path for the starterkit before trying to fetch it...");
     }
     // set default attributes
     $sourceDir = Config::getOption("sourceDir");
     $tempDir = sys_get_temp_dir();
     $tempDirSK = $tempDir . DIRECTORY_SEPARATOR . "pl-sk-archive";
     $tempDirDist = $tempDirSK . DIRECTORY_SEPARATOR . "dist";
     $tempComposerFile = $tempDirSK . DIRECTORY_SEPARATOR . "composer.json";
     // figure out the options for the GH path
     list($org, $repo, $tag) = $this->getPackageInfo($starterkit);
     //get the path to the GH repo and validate it
     $tarballUrl = "https://github.com/" . $org . "/" . $repo . "/archive/" . $tag . ".tar.gz";
     Console::writeInfo("downloading the starterkit...");
     // try to download the given package
     if (!($package = @file_get_contents($tarballUrl))) {
         $error = error_get_last();
         Console::writeError("the starterkit wasn't downloaded because:\n\n  " . $error["message"]);
     }
     // write the package to the temp directory
     $tempFile = tempnam($tempDir, "pl-sk-archive.tar.gz");
     file_put_contents($tempFile, $package);
     Console::writeInfo("finished downloading the starterkit...");
     // make sure the temp dir exists before copying into it
     if (!is_dir($tempDirSK)) {
         mkdir($tempDirSK);
     }
     // extract, if the zip is supposed to be unpacked do that (e.g. stripdir)
     $zippy = Zippy::load();
     $zippy->addStrategy(new UnpackFileStrategy());
     $zippy->getAdapterFor('tar.gz')->open($tempFile)->extract($tempDirSK);
     // thrown an error if temp/dist/ doesn't exist
     if (!is_dir($tempDirDist)) {
         Console::writeError("the starterkit needs to contain a dist/ directory before it can be installed...");
     }
     // check for composer.json. if it exists use it for determining things. otherwise just mirror dist/ to source/
     if (file_exists($tempComposerFile)) {
         $tempComposerJSON = json_decode(file_get_contents($tempComposerFile), true);
         // see if it has a patternlab section that might define the files to move
         if (isset($tempComposerJSON["extra"]) && isset($tempComposerJSON["extra"]["patternlab"])) {
             Console::writeInfo("installing the starterkit...");
             InstallerUtil::parseComposerExtraList($tempComposerJSON["extra"]["patternlab"], $starterkit, $tempDirDist);
             Console::writeInfo("installed the starterkit...");
         } else {
             $this->mirrorDist($sourceDir, $tempDirDist);
         }
     } else {
         $this->mirrorDist($sourceDir, $tempDirDist);
     }
     // remove the temp files
     Console::writeInfo("cleaning up the temp files...");
     $fs = new Filesystem();
     $fs->remove($tempFile);
     $fs->remove($tempDir);
     Console::writeInfo("the starterkit installation is complete...");
     return true;
 }
예제 #4
0
 /**
  * @return \Alchemy\Zippy\Zippy
  */
 public static function load()
 {
     $zippy = Zippy::load();
     $adapters = AdapterContainer::load();
     $zippy->addStrategy(new ZipExtensionFileStrategy($adapters));
     return $zippy;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $httpClient = $this->getHttpClientHelper();
     $siteName = $input->getArgument('site-name');
     $version = $input->getArgument('version');
     if ($version) {
         $releaseSelected = $version;
     } else {
         // Getting Module page header and parse to get module Node
         $io->info(sprintf($this->trans('commands.site.new.messages.getting-releases')));
         // Page for Drupal releases filter by Drupal 8
         $projectReleaseSelected = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234';
         // Parse release module page to get Drupal 8 releases
         try {
             $html = $httpClient->getHtml($projectReleaseSelected);
         } catch (\Exception $e) {
             $io->error($e->getMessage());
             return;
         }
         $crawler = new Crawler($html);
         $releases = [];
         foreach ($crawler->filter('span.file a') as $element) {
             if (strpos($element->nodeValue, ".tar.gz") > 0) {
                 $releaseName = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue));
                 $releases[$releaseName] = $element->nodeValue;
             }
         }
         if (empty($releases)) {
             $io->error($this->trans('commands.site.new.messages.no-releases'));
             return;
         }
         $releaseSelected = $io->choice($this->trans('commands.site.new.messages.release'), array_keys($releases));
     }
     $releaseFilePath = 'http://ftp.drupal.org/files/projects/drupal-' . $releaseSelected . '.tar.gz';
     // Destination file to download the release
     $destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz";
     try {
         // Start the process to download the zip file of release and copy in contrib folter
         $io->info(sprintf($this->trans('commands.site.new.messages.downloading'), $releaseSelected));
         $httpClient->downloadFile($releaseFilePath, $destination);
         $io->info(sprintf($this->trans('commands.site.new.messages.extracting'), $releaseSelected));
         $zippy = Zippy::load();
         $archive = $zippy->open($destination);
         $archive->extract('./');
         try {
             $filesyStem = new Filesystem();
             $filesyStem->rename('./drupal-' . $releaseSelected, './' . $siteName);
         } catch (IOExceptionInterface $e) {
             $io->error(sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()));
         }
         $io->success(sprintf($this->trans('commands.site.new.messages.downloaded'), $releaseSelected, $siteName));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return false;
     }
     return true;
 }
예제 #6
0
 public function register()
 {
     $this->app->bind('backup.zippy', function () {
         return Zippy::load();
     });
     \Event::listen('admin::menu.load', function ($menu) {
         $format = '<img src="%s" class="fa" />&nbsp;&nbsp;<span>%s</span>';
         $menu->add(sprintf($format, moduleAsset('backup', 'images/icon_backup.png'), 'Backup'), route('admin.backup.index'));
     });
 }
 public function uploadDir($container, $dir, $cdnDir = '', $dirTrim = '')
 {
     $temp_file = storage_path() . '/CDN-' . time() . '.tar.gz';
     $zip_dir_name = 0 === strpos($dir, $dirTrim) ? substr($dir, strlen($dirTrim) + 1) : $dir;
     $zippy = Zippy::load();
     // creates an archive.zip that contains a directory "folder" that contains
     // files contained in "/path/to/directory" recursively
     $archive = $zippy->create($temp_file, array($cdnDir . '/' . $zip_dir_name => $dir), true);
     $cdnFile = $this->createDataObject($container, $temp_file, '/', 'tar.gz');
     File::delete($temp_file);
     return $cdnFile;
 }
예제 #8
0
 /**
  * @param $file
  * @param $dest
  * @return string
  */
 public function zip_upload($file, $dest)
 {
     $zippy = Zippy::load();
     $archive = $zippy->open($file);
     $archive->extract($dest);
     $files = array();
     $files[0] = '';
     foreach ($archive as $member) {
         array_push($files, (string) $member);
     }
     unlink($file);
     return json_encode($files);
 }
예제 #9
0
 function download()
 {
     $blocks = array_keys((array) \Larakit\Makeup\Manager::$blocks);
     $themes = ['default' => 'default'] + \Larakit\Page\PageTheme::getThemes();
     $pages = array_keys((array) \Larakit\Makeup\Manager::$pages);
     $contents = ['!' => public_path('!/'), 'packages' => public_path('packages')];
     $tmp_names = [];
     if (!is_dir(storage_path('makeup/'))) {
         mkdir(storage_path('makeup/'), 0777, true);
     }
     $digest = [];
     foreach ($pages as $page) {
         foreach ($themes as $theme) {
             $name = 'page_' . $page . '--' . $theme . '.html';
             $url = url('/makeup/frame-page-' . $page . '?theme=' . $theme);
             $content = $this->prepare_content($url);
             $tmp_name = storage_path('makeup/' . $name);
             file_put_contents($tmp_name, $content);
             $contents[$name] = fopen($tmp_name, 'r');
             $tmp_names[] = $tmp_name;
             $digest['pages'][$page][$theme] = $name;
         }
     }
     foreach ($blocks as $block) {
         foreach ($themes as $theme) {
             $name = 'block_' . $block . '--' . $theme . '.html';
             $url = url('/makeup/frame-block-' . $block . '?theme=' . $theme);
             $content = $this->prepare_content($url);
             $tmp_name = storage_path('makeup/' . $name);
             file_put_contents($tmp_name, $content);
             $contents[$name] = fopen($tmp_name, 'r');
             $tmp_names[] = $tmp_name;
             $digest['blocks'][$block][$theme] = $name;
         }
     }
     $tmp_name = storage_path('makeup/index.html');
     //        $tmp_names[]     = $tmp_name;
     file_put_contents($tmp_name, \View::make('lk-makeup::!.digest', ['digest' => $digest])->__toString());
     $contents['index.html'] = fopen($tmp_name, 'r');
     //        dd(compact('path', 'theme', 'url', 'content'));
     // Creates an archive.zip that contains a directory "folder" that contains
     // files contained in "/path/to/directory" recursively
     // Load Zippy
     $zip_path = storage_path(date('H_i_s') . '.zip');
     $zippy = Zippy::load();
     $zippy->create($zip_path, $contents, true);
     foreach ($tmp_names as $tmp_name) {
         unlink($tmp_name);
     }
     return \Response::download($zip_path);
 }
예제 #10
0
 public function zip()
 {
     $pathList = request('path_list');
     $packageName = request('package_name');
     if (empty($packageName)) {
         $packageName = date("Y-m-d_His");
     }
     $pathList = explode("\n", $pathList);
     $myCodeStoragePath = config('qidian.php_code_storage_path');
     $newList = array();
     foreach ($pathList as $key => $path) {
         if (empty($path)) {
             continue;
         }
         $path = trim(preg_replace('/^\\//', '', $path));
         $source = $myCodeStoragePath . '/' . $path;
         //echo $myCodeStoragePath .'/' . $path;die();
         if (!is_dir($source) && is_file($source)) {
             $basename = basename($source);
             $pathname = dirname($path);
             $dest = PUBLIC_PATH . '/files/' . $packageName . '/' . $pathname;
             if (!is_dir($dest)) {
                 mkdir($dest, 0777, true);
             }
             copy($source, $dest . '/' . $basename);
         } else {
             if (is_dir($source)) {
                 $pathname = dirname($path);
                 $dest = PUBLIC_PATH . '/files/' . $packageName . '/' . $path;
                 if (!is_dir($dest)) {
                     mkdir($dest, 0777, true);
                 }
                 $this->copyDir($source, $dest);
             }
         }
         $newList[] = $path;
     }
     if (empty($newList)) {
         $this->session->set("package.error", trans('package.empty_path_list'));
         return redirect('/package');
     }
     $zip = Zippy::load();
     $zipPath = PUBLIC_PATH . '/files/' . $packageName . '.zip';
     $zip->create($zipPath, PUBLIC_PATH . '/files/' . $packageName);
     $this->downloadFile($zipPath);
     unlink($zipPath);
     $this->delDir(PUBLIC_PATH . '/files/' . $packageName);
 }
예제 #11
0
 /**
  * Build task.
  *
  * @return bool
  */
 public function build()
 {
     $this->say('Build task');
     $envFile = __DIR__ . '/.env.dist';
     if (!file_exists($envFile)) {
         $this->yell(sprintf('The environment "%s" file does not exist!', $envFile));
         return false;
     }
     $buildPath = $this->getBuildPath();
     $filename = 'api_' . time() . '.zip';
     $this->say("Creating archive {$filename} in {$buildPath}");
     $zippy = Zippy::load();
     $zippy->create("{$buildPath}/{$filename}", ['app' => __DIR__ . '/app', 'bootstrap' => __DIR__ . '/bootstrap', 'config' => __DIR__ . '/config', 'data' => __DIR__ . '/data', 'deploy' => __DIR__ . '/deploy', 'public' => __DIR__ . '/public', 'resources' => __DIR__ . '/resources', 'vendor' => __DIR__ . '/vendor', 'artisan' => __DIR__ . '/artisan', '.env' => $envFile]);
     $this->say("Done!");
     return true;
 }
 /**
  * Executes a command via CLI
  *
  * @param Console\Input\InputInterface $input
  * @param Console\Output\OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $tempFolder = $input->getOption('temp-folder');
     $destinationFolder = $input->getOption('src-destination');
     if (empty($destinationFolder)) {
         $destinationFolder = realpath(__DIR__ . '/../../../../');
     }
     if (!is_writable($destinationFolder)) {
         $output->writeln('Chash update failed: the "' . $destinationFolder . '" directory used to update the Chash file could not be written');
         return 0;
     }
     if (!is_writable($tempFolder)) {
         $output->writeln('Chash update failed: the "' . $tempFolder . '" directory used to download the temp file could not be written');
         return 0;
     }
     //$protocol = extension_loaded('openssl') ? 'https' : 'http';
     $protocol = 'http';
     $rfs = new RemoteFilesystem(new NullIO());
     // Chamilo version
     //$latest = trim($rfs->getContents('version.chamilo.org', $protocol . '://version.chamilo.org/version.php', false));
     //https://github.com/chamilo/chash/archive/master.zip
     $tempFile = $tempFolder . '/chash-master.zip';
     $rfs->copy('github.com', 'https://github.com/chamilo/chash/archive/master.zip', $tempFile);
     if (!file_exists($tempFile)) {
         $output->writeln('Chash update failed: the "' . $tempFile . '" file could not be written');
         return 0;
     }
     $folderPath = $tempFolder . '/chash';
     if (!is_dir($folderPath)) {
         mkdir($folderPath);
     }
     $zippy = Zippy::load();
     $archive = $zippy->open($tempFile);
     try {
         $archive->extract($folderPath);
     } catch (\Alchemy\Zippy\Exception\RunTimeException $e) {
         $output->writeln("<comment>Chash update failed during unzip.");
         $output->writeln($e->getMessage());
         return 0;
     }
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->mirror($folderPath . '/chash-master', $destinationFolder, null, array('override' => true));
     $output->writeln('Copying ' . $folderPath . '/chash-master to ' . $destinationFolder);
 }
예제 #13
0
 public static function zipOneDay(Carbon $date)
 {
     $begin = $date->copy()->setTime(0, 0, 0);
     $end = $date->copy()->setTime(23, 59, 59);
     $deleteLocs = [];
     $videoLocs = [];
     $videos = Video::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($videos as $video) {
         $deleteLocs[] = $video->location;
         $videoLocs[] = storage_path('app/' . $video->location);
         $video->state = 'zipped';
         $video->save();
     }
     $imageLocs = [];
     $images = Image::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($images as $image) {
         $deleteLocs[] = $image->location;
         $imageLocs[] = storage_path('app/' . $image->location);
         $image->state = 'zipped';
         $image->save();
     }
     $locs = array_merge($videoLocs, $imageLocs);
     if (count($locs) == 0) {
         Log::info('TumblrZip : no file to be ziped.');
         return;
     }
     $zipName = $begin->toDateString() . '.zip';
     $zipLocs = 'zips/' . $zipName;
     $zippy = Zippy::load();
     $zippy->create(storage_path('app/' . $zipLocs), $locs);
     $zip = new Zip();
     $zip->state = 'ziped';
     $zip->error = '';
     $zip->name = $zipName;
     $zip->date = $begin->toDateString();
     $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB';
     $zip->imageSize = count($imageLocs);
     $zip->videoSize = count($videoLocs);
     $zip->location = $zipLocs;
     $zip->save();
     Storage::delete($deleteLocs);
 }
 /**
  * Return a code to know status
  *  0 = No problem
  *  1 = One file on extracted archive maybe corrupted
  *  2 = One file is not extracted
  *  3 = Archive can't be open
  * @param string $path
  * @return int
  */
 public function isAlreadyExtracted($path)
 {
     $archive = Zippy::load();
     try {
         $readArchive = $archive->open($this->archiveFile);
         $archiveContent = $readArchive->getMembers();
     } catch (\Exception $e) {
         return 3;
     }
     foreach ($archiveContent as $file) {
         if ($file->isDir()) {
             continue;
         }
         if (!$this->fs->exists($path . $file->getLocation())) {
             return 2;
         }
         if (filesize($path . $file->getLocation()) != $file->getSize()) {
             return 1;
         }
     }
     return 0;
 }
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  * @param $project
  * @param $version
  * @param $type
  * @param $path
  *
  * @return string
  */
 public function downloadProject(DrupalStyle $io, $project, $version, $type, $path = null)
 {
     $commandKey = str_replace(':', '.', $this->getName());
     $io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.downloading'), $project, $version));
     try {
         $destination = $this->getApplication()->getDrupalApi()->downloadProjectRelease($project, $version);
         if (!$path) {
             $path = $this->getExtractPath($type);
         }
         $drupal = $this->get('site');
         $projectPath = sprintf('%s/%s', $drupal->isValidInstance() ? $drupal->getRoot() : getcwd(), $path);
         if (!file_exists($projectPath)) {
             if (!mkdir($projectPath, 0777, true)) {
                 $io->error($this->trans('commands.' . $commandKey . '.messages.error-creating-folder') . ': ' . $projectPath);
                 return null;
             }
         }
         $zippy = Zippy::load();
         if (PHP_OS === "WIN32" || PHP_OS === "WINNT") {
             $container = AdapterContainer::load();
             $container['Drupal\\Console\\Zippy\\Adapter\\TarGzGNUTarForWindowsAdapter'] = function ($container) {
                 return TarGzGNUTarForWindowsAdapter::newInstance($container['executable-finder'], $container['resource-manager'], $container['gnu-tar.inflator'], $container['gnu-tar.deflator']);
             };
             $zippy->addStrategy(new TarGzFileForWindowsStrategy($container));
         }
         $archive = $zippy->open($destination);
         if ($type == 'core') {
             $archive->extract(getenv('MSYSTEM') ? null : $projectPath);
         } elseif (getenv('MSYSTEM')) {
             $current_dir = getcwd();
             $temp_dir = sys_get_temp_dir();
             chdir($temp_dir);
             $archive->extract();
             $fileSystem = new Filesystem();
             $fileSystem->rename($temp_dir . '/' . $project, $projectPath . '/' . $project);
             chdir($current_dir);
         } else {
             $archive->extract($projectPath);
         }
         unlink($destination);
         if ($type != 'core') {
             $io->success(sprintf($this->trans('commands.' . $commandKey . '.messages.downloaded'), $project, $version, sprintf('%s/%s', $projectPath, $project)));
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return null;
     }
     return $projectPath;
 }
예제 #16
0
 /**
  * @param OutputInterface $output
  * @param string $version
  * @param string $updateInstallation
  * @param string $defaultTempFolder
  * @return int|null|String
  */
 public function getPackage(OutputInterface $output, $version, $updateInstallation, $defaultTempFolder)
 {
     $fs = new Filesystem();
     $versionTag = $version;
     // Download the chamilo package from from github:
     if (empty($updateInstallation)) {
         $updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/v" . $version . ".zip";
         switch ($version) {
             case 'master':
                 $updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/master.zip";
                 break;
             case '1.9.x':
                 $updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/1.9.x.zip";
                 break;
             case '1.10.x':
                 $updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/1.10.x.zip";
                 break;
             case '1.11.x':
                 $updateInstallation = "https://github.com/chamilo/chamilo-lms/archive/1.11.x.zip";
                 break;
         }
     }
     $updateInstallationOriginal = $updateInstallation;
     if (!empty($updateInstallation)) {
         // Check temp folder
         if (!is_writable($defaultTempFolder)) {
             $output->writeln("<comment>We don't have permissions to write in the temp folder: {$defaultTempFolder}</comment>");
             return 0;
         }
         // Download file?
         if (strpos($updateInstallation, 'http') === false) {
             if (!file_exists($updateInstallation)) {
                 $output->writeln("<comment>File does not exists: {$updateInstallation}</comment>");
                 return 0;
             }
         } else {
             $urlInfo = parse_url($updateInstallation);
             $updateInstallationLocalName = $defaultTempFolder . '/' . basename($urlInfo['path']);
             if (!file_exists($updateInstallationLocalName)) {
                 $output->writeln("<comment>Executing</comment> <info>wget -O {$updateInstallationLocalName} '{$updateInstallation}'</info>");
                 $output->writeln('');
                 $execute = "wget -O " . $updateInstallationLocalName . " '{$updateInstallation}'\n";
                 $systemOutput = shell_exec($execute);
                 $systemOutput = str_replace("\n", "\n\t", $systemOutput);
                 $output->writeln($systemOutput);
             } else {
                 $output->writeln("<comment>Seems that the chamilo v" . $version . " has been already downloaded. File location:</comment> <info>{$updateInstallationLocalName}</info>");
             }
             $updateInstallation = $updateInstallationLocalName;
             if (!file_exists($updateInstallationLocalName)) {
                 $output->writeln("<error>Can't download the file!</error>");
                 $output->writeln("<comment>Check if you can download this file in your browser first:</comment> <info>{$updateInstallation}</info>");
                 return 0;
             }
         }
         if (file_exists($updateInstallation)) {
             $zippy = Zippy::load();
             $archive = $zippy->open($updateInstallation);
             $folderPath = $defaultTempFolder . '/chamilo-v' . $version . '-' . date('y-m-d');
             if (!is_dir($folderPath)) {
                 $fs->mkdir($folderPath);
             } else {
                 // Load from cache
                 $chamiloPath = $folderPath . '/chamilo-lms-CHAMILO_' . $versionTag . '_STABLE/main/inc/global.inc.php';
                 if (file_exists($chamiloPath)) {
                     $output->writeln("<comment>Files have been already extracted here: </comment><info>" . $folderPath . '/chamilo-lms-CHAMILO_' . $versionTag . '_STABLE/' . "</info>");
                     return $folderPath . '/chamilo-lms-CHAMILO_' . $versionTag . '_STABLE/';
                 }
             }
             $location = null;
             if (is_dir($folderPath)) {
                 $output->writeln("<comment>Extracting files here:</comment> <info>{$folderPath}</info>");
                 try {
                     $archive->extract($folderPath);
                     /** @var \Alchemy\Zippy\Archive\Member $member */
                     foreach ($archive as $member) {
                         if (isset($member)) {
                             if ($member->isDir()) {
                                 $location = $member->getLocation();
                                 $globalFile = $folderPath . '/' . $location . 'main/inc/global.inc.php';
                                 if (file_exists($globalFile) && is_file($globalFile)) {
                                     $location = realpath($folderPath . '/' . $location) . '/';
                                     $output->writeln('<comment>Chamilo global.inc.php file detected:</comment> <info>' . $location . 'main/inc/lib/global.inc.php</info>');
                                     break;
                                 }
                             }
                         }
                     }
                 } catch (\Alchemy\Zippy\Exception\RunTimeException $e) {
                     $output->writeln("<comment>It seems that this file doesn't contain a Chamilo package:</comment> <info>{$updateInstallationOriginal}</info>");
                     unlink($updateInstallation);
                     $output->writeln("<comment>Removing file</comment>:<info>{$updateInstallation}</info>");
                     //$output->writeln("Error:");
                     //$output->writeln($e->getMessage());
                     return 0;
                 }
             }
             $chamiloLocationPath = $location;
             if (empty($chamiloLocationPath)) {
                 $output->writeln("<error>Chamilo folder structure not found in package.</error>");
                 return 0;
             }
             return $chamiloLocationPath;
         } else {
             $output->writeln("<comment>File doesn't exist.</comment>");
             return 0;
         }
     }
     return 0;
 }
 /**
  *
  * Prepare file for storing on defined storage like G Drive, FTP or local place
  *
  * @param string $type mysql or local files
  * @param array $details
  */
 private function prepareForStoring($type, $details = array())
 {
     $zippy = Zippy::load();
     $filename = $this->backupPath . date("Y-m-d-H-i-s") . "-" . $type . "." . $this->archiveType;
     if (is_dir($details['full_path'])) {
         $zippy->create($filename, array($details['full_path']), $recursive = true);
     } else {
         $zippy->create($filename, array($details['full_path']), $recursive = false);
     }
     $this->filesToStore[] = array('type' => $type, 'file_path' => $filename, 'file_name' => $details['backup_name'] . "." . $this->archiveType, 'backup_name' => $details['backup_name'], 'host' => $details['host']);
     $filesystem = new Filesystem();
     $filesystem->remove($details['full_path']);
 }
예제 #18
0
 protected function processRequestTicket(DataPacket $data, &$files)
 {
     /** @var Request $request */
     $request = app(Request::class);
     $input = $request->only(['operator', 'tariff', 'simcard']);
     $ticket = $this->getRandomUUID(false);
     $imagesList = ['list1', 'list2', 'list2_uv', 'list1_uv', 'list3', 'list4', 'photo', 'dogovor'];
     $images = [];
     foreach ($imagesList as $key => $image) {
         if ($request->hasFile($image)) {
             $img = $request->file($image);
             $images[$key + 1 . '.jpg'] = $img->getRealPath();
         }
     }
     if (!empty($images)) {
         $fileName = time() . '_' . $ticket . '.1.zip';
         $zippy = Zippy::load();
         $zippy->create(storage_path('app/' . $fileName), $images);
         $files['uploadfile'] = storage_path('app/' . $fileName);
         $data->addPair('FileTypeParts', 1);
         $data->addPair('FileTotalParts', 1);
         $data->addPair('FileName', $fileName);
         $data->addPair('HashFile', md5_file(storage_path('app/' . $fileName)));
     }
     extract($input, EXTR_OVERWRITE);
     $data->addPair('global_id', $ticket);
     $data->addPair('tarif', $tariff);
     $data->addPair('SimCardCode', $simcard);
     /*
             CountDogovorWasPrinted
             PassportValidation
     */
     app(SessionInterface::class)->set('view.RequestTicket.data', $input);
 }
예제 #19
0
 /**
  * Send ticket.
  *
  * @param Request $request
  * @param $server
  * @param $terminal
  */
 public function ticket(TerminalSender $sender, Request $request, $server, $terminal)
 {
     $server = Server::query()->findOrFail($server);
     $terminal = $server->terminals()->findOrFail($terminal);
     $ticket = $this->getRandomUUID(false);
     $imagesList = ['list1', 'list2', 'list2_uv', 'list1_uv', 'list3', 'list4', 'photo', 'dogovor'];
     $images = $files = [];
     foreach ($imagesList as $key => $image) {
         if ($request->hasFile($image)) {
             $img = $request->file($image);
             $images[$key + 1 . '.jpg'] = $img->getRealPath();
         }
     }
     $sender->setCredentials($server->uri, $terminal->guid, $terminal->password);
     $packet = new DataPacket();
     if (!empty($images)) {
         $fileName = time() . '_' . $ticket . '.1.zip';
         $zippy = Zippy::load();
         $zippy->create(storage_path('app/' . $fileName), $images);
         $files['uploadfile'] = storage_path('app/' . $fileName);
         $packet->addPair('FileTypeParts', 1);
         $packet->addPair('FileTotalParts', 1);
         $packet->addPair('FileName', $fileName);
         $packet->addPair('HashFile', md5_file(storage_path('app/' . $fileName)));
     }
     $packet->addPair('global_id', $ticket);
     $packet->addPair('tarif', $request->input('tariff'));
     $packet->addPair('SimCardCode', $request->input('simcard'));
     $packet->addPair('PhoneNumber', '');
     $packet->addPair('PassportValidation', '');
     $result = $sender->send('RequestTicket', $packet, $files);
     /*
             CountDogovorWasPrinted
             PassportValidation
     */
     list($data, $required) = $sender->parseResult($result);
     if (Arr::get($required, 'Result') != 'OK') {
         throw new \RuntimeException();
     }
     $messages = [];
     if ($guid = Arr::get($result, 'global_id')) {
         $messages[] = 'Заявка создана: ' . $guid;
     }
     if ($error = Arr::get($result, 'ErrorMessage')) {
         $messages[] = $error;
     }
     return redirect()->action('\\' . static::class . '@index', [$server->id])->with('message-success', $messages);
 }
예제 #20
0
 /**
  * Zip temp dir
  */
 function zip()
 {
     $zippy = Zippy::load();
     $zippy->create($this->zip, array("./" => $this->dir), true);
 }
예제 #21
0
 /** @test */
 public function loadShouldRegisterStrategies()
 {
     $zippy = Zippy::load();
     $this->assertCount(7, $zippy->getStrategies());
     $this->assertArrayHasKey('zip', $zippy->getStrategies());
     $this->assertArrayHasKey('tar', $zippy->getStrategies());
     $this->assertArrayHasKey('tar.gz', $zippy->getStrategies());
     $this->assertArrayHasKey('tar.bz2', $zippy->getStrategies());
     $this->assertArrayHasKey('tbz2', $zippy->getStrategies());
     $this->assertArrayHasKey('tb2', $zippy->getStrategies());
     $this->assertArrayHasKey('tgz', $zippy->getStrategies());
 }
 function test_zip()
 {
     global $jekyll_export;
     file_put_contents($jekyll_export->dir . "/foo.txt", "bar");
     $jekyll_export->zip();
     $this->assertTrue(file_exists($jekyll_export->zip));
     $zippy = Zippy::load();
     $archive = $zippy->open($jekyll_export->zip);
     $temp_dir = get_temp_dir() . "jekyll-export-extract";
     system("rm -rf " . escapeshellarg($temp_dir));
     mkdir($temp_dir);
     $archive->extract($temp_dir);
     $this->assertTrue(file_exists($temp_dir . "/foo.txt"));
     $this->assertEquals("bar", file_get_contents($temp_dir . "/foo.txt"));
 }
예제 #23
0
        Filesystem::delete($distfolder);
        Folder::create($distfolder);
    }
    $task->writeln('Copying files over.');
    recursiveCopy('dev', $basepath, $distfolder);
    $task->writeln('Running composer');
    $task->exec(function ($process) {
        $basepath = realpath(__DIR__ . '/..');
        $distfolder = Path::clean($basepath . '/dist');
        $distfolder = str_replace(' ', '\\ ', $distfolder);
        $process->runLocally("cd " . $distfolder . '/dev' . " && composer install --prefer-dist --optimize-autoloader");
        $process->runLocally("cd .. && cd ..");
    });
    Folder::move($distfolder . '/dev', $distfolder . '/notify');
    $task->writeln('Zipping');
    $zippy = Zippy::load();
    $archive = $zippy->create('flarum-notify.zip', array('notify' => $distfolder . '/notify'));
    $task->writeln('Deleting copied folder');
    Folder::delete($distfolder . '/notify');
    File::move($basepath . '/flarum-notify.zip', $distfolder . '/flarum-notify.zip');
})->description("Builds a release ready package from the current project state and stores it in /dist.");
function recursiveCopy($filename, $initialfolder, $targetfolder)
{
    $badfiles = ['vendor', 'node_modules', '.DS_Store', 'sftp-config.json', '.git', '.gitignore', 'build.sh'];
    foreach (Folder::items($initialfolder . '/' . $filename, false, Folder::PATH_BASENAME) as $item) {
        if (!in_array($item, $badfiles)) {
            if (is_dir($initialfolder . '/' . $filename . '/' . $item)) {
                recursiveCopy($item, $initialfolder . '/' . $filename, $targetfolder . '/' . $filename);
            } else {
                File::copy($initialfolder . '/' . $filename . '/' . $item, $targetfolder . '/' . $filename . '/' . $item);
            }
예제 #24
0
 public function register(Application $app)
 {
     $app['zippy'] = $app->share(function () {
         return Zippy::load();
     });
 }
예제 #25
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!class_exists('GuzzleHttp\\Client')) {
         throw new \Exception(sprintf('This command is disabled, for more information visit issue(s) %s %s', "\r\n" . 'https://www.drupal.org/node/2538484', "\r\n" . 'https://github.com/hechoendrupal/DrupalConsole/issues/767' . "\r\n"));
     }
     $client = new Client();
     $site_name = $input->getArgument('site-name');
     $version = $input->getArgument('version');
     if ($version) {
         $release_selected = '8.x-' . $version;
     } else {
         // Getting Module page header and parse to get module Node
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.getting-releases')) . '</info>');
         // Page for Drupal releases filter by Drupal 8
         $project_release_d8 = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234';
         // Parse release module page to get Drupal 8 releases
         try {
             $response = $client->get($project_release_d8);
             $html = $response->getBody()->__tostring();
         } catch (\Exception $e) {
             $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
             return;
         }
         $crawler = new Crawler($html);
         $releases = [];
         foreach ($crawler->filter('span.file a') as $element) {
             if (strpos($element->nodeValue, ".tar.gz") > 0) {
                 $release_name = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue));
                 $releases[$release_name] = $element->nodeValue;
             }
         }
         if (empty($releases)) {
             $output->writeln('[+] <error>' . $this->trans('commands.module.site.new.no-releases') . '</error>');
             return;
         }
         // List module releases to enable user to select his favorite release
         $questionHelper = $this->getQuestionHelper();
         $question = new ChoiceQuestion('Please select your favorite release', array_combine(array_keys($releases), array_keys($releases)), 0);
         $release_selected = $questionHelper->ask($input, $output, $question);
         // Start the process to download the zip file of release and copy in contrib folter
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloading'), $release_selected) . '</info>');
     }
     $release_file_path = 'http://ftp.drupal.org/files/projects/drupal-' . $release_selected . '.tar.gz';
     // Destination file to download the release
     $destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz";
     $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.extracting'), $release_selected) . '</info>');
     try {
         $client->get($release_file_path, ['save_to' => $destination]);
         // Prepare release to unzip and untar
         $zippy = Zippy::load();
         $archive = $zippy->open($destination);
         $archive->extract('./');
         try {
             $fs = new Filesystem();
             $fs->rename('./drupal-' . $release_selected, './' . $site_name);
         } catch (IOExceptionInterface $e) {
             $output->writeln('[+] <error>' . sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()) . '</error>');
         }
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloaded'), $release_selected, $site_name) . '</info>');
     } catch (\Exception $e) {
         $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
         return;
     }
     return true;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $httpClient = $this->getHttpClientHelper();
     $theme = $input->getArgument('theme');
     $version = $input->getArgument('version');
     if ($version) {
         $release_selected = $version;
     } else {
         // Getting Theme page header and parse to get theme Node
         $io->info(sprintf($this->trans('commands.theme.download.messages.getting-releases'), implode(',', array($theme))));
         try {
             $link = $httpClient->getHeader('https://www.drupal.org/project/' . $theme, 'link');
         } catch (\Exception $e) {
             $io->error($e->getMessage());
             return;
         }
         $header_link = explode(';', $link);
         $project_node = str_replace('<', '', str_replace('>', '', $header_link[0]));
         $project_release_d8 = $project_node . '/release?api_version%5B%5D=7234';
         // Parse release theme page to get Drupal 8 releases
         try {
             $html = $httpClient->getHtml($project_release_d8);
         } catch (\Exception $e) {
             $io->error($e->getMessage());
             return;
         }
         $crawler = new Crawler($html);
         $releases = [];
         foreach ($crawler->filter('span.file a') as $element) {
             if (strpos($element->nodeValue, '.tar.gz') > 0) {
                 $release_name = str_replace('.tar.gz', '', str_replace($theme . '-', '', $element->nodeValue));
                 $releases[$release_name] = $element->nodeValue;
             }
         }
         if (empty($releases)) {
             $io->error(sprintf($this->trans('commands.theme.download.messages.no-releases'), implode(',', array($theme))));
             return;
         }
         // List theme releases to enable user to select his favorite release
         $questionHelper = $this->getQuestionHelper();
         $question = new ChoiceQuestion($this->trans('commands.theme.download.messages.select-release'), array_combine(array_keys($releases), array_keys($releases)), '0');
         $release_selected = $questionHelper->ask($input, $output, $question);
     }
     // Start the process to download the zip file of release and copy in contrib folter
     $io->info(sprintf($this->trans('commands.theme.download.messages.downloading'), $theme, $release_selected));
     $release_file_path = 'http://ftp.drupal.org/files/projects/' . $theme . '-' . $release_selected . '.tar.gz';
     // Destination file to download the release
     $destination = tempnam(sys_get_temp_dir(), 'console.') . '.tar.gz';
     try {
         $httpClient->downloadFile($release_file_path, $destination);
         // Determine destination folder for contrib theme
         $drupal = $this->getDrupalHelper();
         $drupalRoot = $drupal->getRoot();
         if ($drupalRoot) {
             $theme_contrib_path = $drupalRoot . '/themes/contrib';
         } else {
             $io->info(sprintf($this->trans('commands.theme.download.messages.outside-drupal'), $theme, $release_selected));
             $theme_contrib_path = getcwd() . '/themes/contrib';
         }
         // Create directory if does not exist
         if (!file_exists($theme_contrib_path)) {
             if (!mkdir($theme_contrib_path, 0777, true)) {
                 $io->error($this->trans('commands.theme.download.messages.error-creating-folder') . ': ' . $theme_contrib_path);
                 return;
             }
         }
         // Prepare release to unzip and untar
         $zippy = Zippy::load();
         $archive = $zippy->open($destination);
         $archive->extract($theme_contrib_path . '/');
         unlink($destination);
         $io->info(sprintf($this->trans('commands.theme.download.messages.downloaded'), $theme, $release_selected, $theme_contrib_path));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return;
     }
     return true;
 }
예제 #27
0
 /**
  * packCore
  *
  * @return \Alchemy\Zippy\Archive\ArchiveInterface
  * @throws BimException
  */
 public function packCore()
 {
     try {
         $this->dumpMysql();
         $zippy = Zippy::load();
         $archive = $zippy->create($this->getFullPath(), $this->getBitrixCore(), true);
         $this->dataResponse[] = $this->color(strtoupper("completed"), Colors::GREEN) . " : " . $this->getFullPath();
         $this->saveInfoToJson();
         $this->dataResponse[] = $this->color(strtoupper("completed"), Colors::GREEN) . " : " . $this->getSessionDBtFileName();
         return $archive;
     } catch (RuntimeException $e) {
         $this->clearExport();
         throw new BimException("EXPORT ERROR: " . $e->getMessage());
     }
 }