Skip to content

Commit 046bc26

Browse files
author
David Verholen
committed
clean up after rebase
1 parent 4ad97cd commit 046bc26

File tree

2 files changed

+15
-362
lines changed

2 files changed

+15
-362
lines changed

src/MagentoHackathon/Composer/Magento/Installer/CoreInstaller.php

Lines changed: 1 addition & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ public function supports($packageType)
117117
*/
118118
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
119119
{
120-
if (!$this->preInstallMagentoCore()) {
121-
$this->io->write('<error>Failed to process Pre Install operations. Aborting Core Install</error>');
122-
123-
return;
124-
}
125-
126120
parent::install($repo, $package);
127121
}
128122

@@ -137,162 +131,10 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
137131
*/
138132
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
139133
{
140-
if (false === $this->preUpdateMagentoCore()) {
141-
$this->io->write('<error>Failed to process Pre Update operations. Aborting Core Update</error>');
142-
143-
return;
144-
}
145-
146134
parent::update($repo, $initial, $target);
147-
148-
$this->postUpdateMagentoCore();
149-
}
150-
151-
/**
152-
* prepare Magento Core Update
153-
*
154-
* @return bool
155-
*/
156-
protected function preUpdateMagentoCore()
157-
{
158-
if (!$this->io->askConfirmation(
159-
'<info>Are you sure you want to manipulate the Magento core installation</info> [<comment>Y,n</comment>]? ',
160-
true
161-
)
162-
) {
163-
$this->io->write('<info>Skipping core update...</info>');
164-
165-
return false;
166-
}
167-
$tmpDir = $this->getTmpDir();
168-
$this->filesystem->ensureDirectoryExists($tmpDir);
169-
$this->originalMagentoRootDir = clone $this->magentoRootDir;
170-
$this->magentoRootDir = new \SplFileInfo($tmpDir);
171-
172-
return true;
173-
}
174-
175-
protected function getTmpDir()
176-
{
177-
return $this->magentoRootDir->getPathname() . self::MAGENTO_ROOT_DIR_TMP_SUFFIX;
178-
}
179-
180-
protected function getBkpDir()
181-
{
182-
return $this->magentoRootDir->getPathname() . self::MAGENTO_ROOT_DIR_BACKUP_SUFFIX;
183-
}
184-
185-
/**
186-
* Install Magento core
187-
*
188-
* @internal param \Composer\Repository\InstalledRepositoryInterface $repo repository in which to check
189-
* @internal param \Composer\Package\PackageInterface $package package instance
190-
*
191-
* @return bool
192-
*/
193-
protected function preInstallMagentoCore()
194-
{
195-
if (!$this->io->askConfirmation(
196-
'<info>Are you sure you want to install the Magento core?</info><error>Attention: Your Magento root dir will be cleared in the process!</error> [<comment>Y,n</comment>] ',
197-
true
198-
)
199-
) {
200-
$this->io->write('Skipping core installation...');
201-
202-
return false;
203-
}
204-
$this->clearRootDir();
205-
206-
return true;
207-
}
208-
209-
/**
210-
* process post core update tasks
211-
*/
212-
protected function postUpdateMagentoCore()
213-
{
214-
$tmpDir = $this->magentoRootDir->getPathname();
215-
$backupDir = $this->originalMagentoRootDir->getPathname() . self::MAGENTO_ROOT_DIR_BACKUP_SUFFIX;
216-
$this->backupMagentoRootDir = new \SplFileInfo($backupDir);
217-
218-
$origRootDir = $this->originalMagentoRootDir->getPathName();
219-
$this->filesystem->rename($origRootDir, $backupDir);
220-
$this->filesystem->rename($tmpDir, $origRootDir);
221-
$this->magentoRootDir = clone $this->originalMagentoRootDir;
222-
223-
$this->prepareMagentoCore();
224-
$this->cleanupPostUpdateMagentoCore();
225-
}
226-
227-
/**
228-
* prepare Core
229-
*/
230-
public function prepareMagentoCore()
231-
{
232-
$this->setMagentoPermissions();
233-
$this->redeployProject();
234-
}
235-
236-
protected function clearRootDir()
237-
{
238-
$this->filesystem->removeDirectory($this->magentoRootDir->getPathname());
239-
$this->filesystem->ensureDirectoryExists($this->magentoRootDir->getPathname());
240-
}
241-
242-
/**
243-
* clean up after core update
244-
*/
245-
protected function cleanupPostUpdateMagentoCore()
246-
{
247-
$rootDir = $this->magentoRootDir->getPathname();
248-
$backupDir = $this->backupMagentoRootDir->getPathname();
249-
250-
if (file_exists($backupDir . DIRECTORY_SEPARATOR . self::MAGENTO_LOCAL_XML_PATH)) {
251-
copy(
252-
$backupDir . DIRECTORY_SEPARATOR . self::MAGENTO_LOCAL_XML_PATH,
253-
$rootDir . DIRECTORY_SEPARATOR . self::MAGENTO_LOCAL_XML_PATH
254-
);
255-
}
256-
foreach ($this->persistentDirs as $folder) {
257-
$this->filesystem->removeDirectory($rootDir . DIRECTORY_SEPARATOR . $folder);
258-
$this->filesystem->rename(
259-
$backupDir . DIRECTORY_SEPARATOR . $folder, $rootDir . DIRECTORY_SEPARATOR . $folder
260-
);
261-
}
262-
if ($this->io->ask('Remove root backup? [Y,n] ', true)) {
263-
$this->filesystem->removeDirectory($backupDir);
264-
$this->io->write('Removed root backup!', true);
265-
} else {
266-
$this->io->write('Skipping backup removal...', true);
267-
}
268-
$this->clearMagentoCache();
269135
}
270136

271-
/**
272-
* clear Magento Cache
273-
*/
274-
public function clearMagentoCache()
275-
{
276-
if (($targetDir = $this->getTargetDir()) && !$this->keepMagentoCache) {
277-
$magentoCachePath = $targetDir . DIRECTORY_SEPARATOR . self::MAGENTO_CACHE_PATH;
278-
if ($this->filesystem->removeDirectory($magentoCachePath)) {
279-
$this->io->write('Magento cache cleared');
280-
}
281-
}
282-
}
283137

284-
/**
285-
* some directories have to be writable for the server
286-
*/
287-
protected function setMagentoPermissions()
288-
{
289-
foreach ($this->magentoWritableDirs as $dir) {
290-
if (!file_exists($this->getTargetDir() . DIRECTORY_SEPARATOR . $dir)) {
291-
$this->filesystem->ensureDirectoryExists($this->getTargetDir() . DIRECTORY_SEPARATOR . $dir);
292-
}
293-
$this->setPermissions($this->getTargetDir() . DIRECTORY_SEPARATOR . $dir, 0777, 0666);
294-
}
295-
}
296138

297139
/**
298140
* Returns the strategy class used for deployment
@@ -307,58 +149,4 @@ public function getDeployStrategy(PackageInterface $package, $strategy = null)
307149
{
308150
return new Copy($this->getSourceDir($package), $this->getTargetDir());
309151
}
310-
311-
/**
312-
* @param PackageInterface $package
313-
*
314-
* @throws \ErrorException
315-
*/
316-
protected function addEntryToDeployManager(PackageInterface $package) {
317-
$targetStrategy = $this->getDeployStrategy($package);
318-
$targetStrategy->setMappings($this->getParser($package)->getMappings());
319-
$deployManagerEntry = new Entry();
320-
$deployManagerEntry->setPackageName($package->getName());
321-
$deployManagerEntry->setDeployStrategy($targetStrategy);
322-
$deployManagerEntry->getDeployStrategy()->deploy();
323-
}
324-
325-
/**
326-
* @throws \ErrorException
327-
*/
328-
protected function redeployProject()
329-
{
330-
$ioInterface = $this->io;
331-
// init repos
332-
$composer = $this->composer;
333-
$installedRepo = $composer->getRepositoryManager()->getLocalRepository();
334-
335-
$im = $composer->getInstallationManager();
336-
337-
/* @var ModuleInstaller $moduleInstaller */
338-
$moduleInstaller = $im->getInstaller("magento-module");
339-
340-
/* @var PackageInterface $package */
341-
foreach ($installedRepo->getPackages() as $package) {
342-
343-
if ($ioInterface->isVerbose()) {
344-
$ioInterface->write($package->getName());
345-
$ioInterface->write($package->getType());
346-
}
347-
348-
if ($package->getType() != "magento-module") {
349-
continue;
350-
}
351-
if ($ioInterface->isVerbose()) {
352-
$ioInterface->write("package {$package->getName()} recognized");
353-
}
354-
355-
$strategy = $moduleInstaller->getDeployStrategy($package);
356-
if ($ioInterface->getOption('verbose')) {
357-
$ioInterface->write("used " . get_class($strategy) . " as deploy strategy");
358-
}
359-
$strategy->setMappings($moduleInstaller->getParser($package)->getMappings());
360-
361-
$strategy->deploy();
362-
}
363-
}
364-
}
152+
}

0 commit comments

Comments
 (0)