I want to create media directory with 777 recursive permission on custom module installation time, So I have created createDirectory
function in InstallSchema
.
But currently directory is created with drwxrwxr-x
permission. so i want to give 777
permission.
Here is my InstallSchema.php
.
<?php
/**
* VendorNameSpace ModuleName
* Class Description
*/
namespace VendorNameSpace\ModuleName\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
class InstallSchema implements InstallSchemaInterface {
/**
* Blog Post Module's Media Directories
*/
const MEDIA_TMP_PATH = 'vendornamespace/modulename/tmp/upload';
const MEDIA_PATH = 'vendornamespace/modulename/upload';
/**
* @var Magento\Framework\App\Filesystem\DirectoryList
*/
private $_directoryList;
/**
* @var Magento\Framework\Filesystem\Io\File
*/
private $_ioFile;
/**
* @param \Magento\Framework\Filesystem\Io\File $ioFile
* @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
*/
public function __construct(
\Magento\Framework\Filesystem\Io\File $ioFile,
\Magento\Framework\App\Filesystem\DirectoryList $directoryList
) {
$this->_ioFile = $ioFile;
$this->_directoryList = $directoryList;
}
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(
SchemaSetupInterface $setup,
ModuleContextInterface $context
) {
$this->_createMediaDir();
/**
* Database Script
*
*
* ......
*/
}
/**
* Creating Media Directories
*/
protected function _createMediaDir() {
$mediaTemp = $this->_directoryList->getPath(DirectoryList::MEDIA) . DIRECTORY_SEPARATOR . SELF::MEDIA_TMP_PATH;
$media = $this->_directoryList->getPath(DirectoryList::MEDIA) . DIRECTORY_SEPARATOR . SELF::MEDIA_PATH;
$directories = [$media, $mediaTemp];
$ioAdapter = $this->_ioFile;
foreach ($directories as $dir) {
if(!is_dir($dir)){
$ioAdapter->mkdir($dir,0777);
}
}
}
}