Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
CopyService Class Reference

Public Member Functions

 __construct (\Magento\Framework\Filesystem $filesystem, \Magento\Framework\View\Design\Theme\FileFactory $fileFactory, \Magento\Widget\Model\Layout\Link $link, \Magento\Widget\Model\Layout\UpdateFactory $updateFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\View\Design\Theme\Customization\Path $customization)
 
 copy (ThemeInterface $source, ThemeInterface $target)
 

Protected Member Functions

 _copyFilesystemCustomization (ThemeInterface $source, ThemeInterface $target)
 
 _copyFilesRecursively ($baseDir, $sourceDir, $targetDir)
 
 _deleteFilesRecursively ($targetDir)
 

Protected Attributes

 $_directory
 
 $_fileFactory
 
 $_link
 
 $_updateFactory
 
 $_eventManager
 
 $_customizationPath
 

Detailed Description

Definition at line 15 of file CopyService.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Filesystem  $filesystem,
\Magento\Framework\View\Design\Theme\FileFactory  $fileFactory,
\Magento\Widget\Model\Layout\Link  $link,
\Magento\Widget\Model\Layout\UpdateFactory  $updateFactory,
\Magento\Framework\Event\ManagerInterface  $eventManager,
\Magento\Framework\View\Design\Theme\Customization\Path  $customization 
)
Parameters
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\View\Design\Theme\FileFactory$fileFactory
\Magento\Widget\Model\Layout\Link$link
\Magento\Widget\Model\Layout\UpdateFactory$updateFactory
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Framework\View\Design\Theme\Customization\Path$customization

Definition at line 55 of file CopyService.php.

62  {
63  $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
64  $this->_fileFactory = $fileFactory;
65  $this->_link = $link;
66  $this->_updateFactory = $updateFactory;
67  $this->_eventManager = $eventManager;
68  $this->_customizationPath = $customization;
69  }
$filesystem

Member Function Documentation

◆ _copyFilesRecursively()

_copyFilesRecursively (   $baseDir,
  $sourceDir,
  $targetDir 
)
protected

Copies all files in a directory recursively

Parameters
string$baseDir
string$sourceDir
string$targetDir
Returns
void

Definition at line 180 of file CopyService.php.

181  {
182  foreach ($this->_directory->read($sourceDir) as $path) {
183  if ($this->_directory->isDirectory($path)) {
184  $this->_copyFilesRecursively($baseDir, $path, $targetDir);
185  } else {
186  $filePath = substr($path, strlen($baseDir) + 1);
187  $this->_directory->copyFile($path, $targetDir . '/' . $filePath);
188  }
189  }
190  }
$baseDir
Definition: autoload.php:9
_copyFilesRecursively($baseDir, $sourceDir, $targetDir)

◆ _copyFilesystemCustomization()

_copyFilesystemCustomization ( ThemeInterface  $source,
ThemeInterface  $target 
)
protected

Copy customizations stored in a file system from one theme to another, overriding existing data

Parameters
ThemeInterface$source
ThemeInterface$target
Returns
void

Definition at line 156 of file CopyService.php.

157  {
158  $sourcePath = $this->_customizationPath->getCustomizationPath($source);
159  $targetPath = $this->_customizationPath->getCustomizationPath($target);
160 
161  if (!$sourcePath || !$targetPath) {
162  return;
163  }
164 
165  $this->_deleteFilesRecursively($targetPath);
166 
167  if ($this->_directory->isDirectory($sourcePath)) {
168  $this->_copyFilesRecursively($sourcePath, $sourcePath, $targetPath);
169  }
170  }
$source
Definition: source.php:23
$target
Definition: skip.phtml:8
_copyFilesRecursively($baseDir, $sourceDir, $targetDir)

◆ _deleteFilesRecursively()

_deleteFilesRecursively (   $targetDir)
protected

Delete all files in a directory recursively

Parameters
string$targetDir
Returns
void

Definition at line 198 of file CopyService.php.

199  {
200  if ($this->_directory->isExist($targetDir)) {
201  foreach ($this->_directory->read($targetDir) as $path) {
202  $this->_directory->delete($path);
203  }
204  }
205  }

◆ copy()

copy ( ThemeInterface  $source,
ThemeInterface  $target 
)

Copy customizations from one theme to another

Parameters
ThemeInterface$source
ThemeInterface$target
Returns
void

Definition at line 78 of file CopyService.php.

79  {
80  $this->_copyDatabaseCustomization($source, $target);
81  $this->_copyLayoutCustomization($source, $target);
83  }
_copyFilesystemCustomization(ThemeInterface $source, ThemeInterface $target)
$source
Definition: source.php:23
$target
Definition: skip.phtml:8

Field Documentation

◆ $_customizationPath

$_customizationPath
protected

Definition at line 45 of file CopyService.php.

◆ $_directory

$_directory
protected

Definition at line 20 of file CopyService.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 40 of file CopyService.php.

◆ $_fileFactory

$_fileFactory
protected

Definition at line 25 of file CopyService.php.

◆ $_link

$_link
protected

Definition at line 30 of file CopyService.php.

◆ $_updateFactory

$_updateFactory
protected

Definition at line 35 of file CopyService.php.


The documentation for this class was generated from the following file: