Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Synchronization.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
24  protected $storageFactory;
25 
31  protected $mediaDirectory;
32 
37  public function __construct(
38  DatabaseFactory $storageFactory,
39  DirectoryWrite $directory
40  ) {
41  $this->storageFactory = $storageFactory;
42  $this->mediaDirectory = $directory;
43  }
44 
52  public function synchronize($relativeFileName)
53  {
55  $storage = $this->storageFactory->create();
56  try {
57  $storage->loadByFilename($relativeFileName);
58  } catch (\Exception $e) {
59  }
60  if ($storage->getId()) {
62  $file = $this->mediaDirectory->openFile($relativeFileName, 'w');
63  try {
64  $file->lock();
65  $file->write($storage->getContent());
66  $file->unlock();
67  $file->close();
68  } catch (FileSystemException $e) {
69  $file->close();
70  }
71  }
72  }
73 }
__construct(DatabaseFactory $storageFactory, DirectoryWrite $directory)