Yii2, change permission on backend/web/assets - permissions

I am using Yii2, advanced applications.
Is there a way to change the directory permission of the folders created in the assets folder backend/web/assets.
By default it is 775, I want to make them 755
I want to make this change, maybe from Yii config and not from the terminal.

You should simply change AssetManager property dirMode in your config file :
$dirMode : The permission to be set for newly generated asset directories. This value will be used by PHP chmod() function. No umask will be applied. Defaults to 0775, meaning the directory is read-writable by owner and group, but read-only for other users.
e.g. :
'assetManager' => [
'dirMode' => 0755,
// ...
],

Another approach for Yii2 advanced:
Go to your project root directory, open this file your-yii2-project/environments/index.php and see given permissions:
return [
'Development' => [
'path' => 'dev',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
'frontend/runtime',
'frontend/web/assets',
],
'setExecutable' => [
'yii',
'tests/codeception/bin/yii',
],
'setCookieValidationKey' => [
'backend/config/main-local.php',
'frontend/config/main-local.php',
],
],

Related

How can i add a module in odoo15

I use mac to study odoo,
And i use this document to build my first module with command
./odoo-bin --addons-path=/Users/xuhongxin/src/custom,addons
And i successfully start the odoo,
But i can not find the estate module;
How can i solve this problem?
the document is :
https://www.odoo.com/documentation/15.0/developer/howtos/rdtraining/03_newapp.html
my manifest.py is :
{
'name': 'estate',
'summary': 'estate',
'description': "estate",
'website': 'https://www.odoo.com/page/crm',
'depends': [
'base_setup',
'sales_team',
'mail',
'calendar',
'resource',
'fetchmail',
'utm',
'web_tour',
'contacts',
'digest',
'phone_validation',
],
'data': [
'security/crm_security.xml',
'security/ir.model.access.csv',
'data/crm_lead_prediction_data.xml',
'data/crm_lost_reason_data.xml',
'data/crm_stage_data.xml',
'data/crm_team_data.xml',
'data/digest_data.xml',
'data/mail_data.xml',
'data/crm_recurring_plan_data.xml',
'wizard/crm_lead_lost_views.xml',
'wizard/crm_lead_to_opportunity_views.xml',
'wizard/crm_lead_to_opportunity_mass_views.xml',
'wizard/crm_merge_opportunities_views.xml',
'views/assets.xml',
'views/calendar_views.xml',
'views/crm_recurring_plan_views.xml',
'views/crm_menu_views.xml',
'views/crm_lost_reason_views.xml',
'views/crm_stage_views.xml',
'views/crm_lead_views.xml',
'views/digest_views.xml',
'views/mail_activity_views.xml',
'views/res_config_settings_views.xml',
'views/res_partner_views.xml',
'views/utm_campaign_views.xml',
'report/crm_activity_report_views.xml',
'report/crm_opportunity_report_views.xml',
'views/crm_team_views.xml',
],
'demo': [
'data/crm_team_demo.xml',
'data/mail_activity_demo.xml',
'data/crm_lead_demo.xml',
],
'css': ['static/src/css/crm.css'],
'installable': True,
'application': True,
'auto_install': False
}
You must pay attention to the path that odoo is having while searching for addons which is where all modules are located. You can check this via running the server in the command line and looking for the path that says is running or taking the info from, mostly is addons directory, make sure your module is running inside that exact path and if not, just add the path to the variable that stores the addons paths.

How to add aliases in yii2?

I have extracted mdmsoft extension in my backend/extensions/mdm folder. Added aliases in backend config main.php
'aliases' => [
'#mdm/admin' => '#backend/extensions/mdm'
]
Added module as
[
'modules' => [
'admin' => [
'class' => 'mdm\admin\Module'
]
]
],
It returns me error.Failed to instantiate component or class "mdm\admin\Module".
How I can manage the config file that MDM works from my backend folder
Maybe you have to add line below:
Yii::setAlias('#mdm', dirname(dirname(__DIR__)) . '/backend/extensions/mdm');
into common/config/bootstrap.php ?

'lessc' is not recognized as an internal or external command, Yii2 WAMP win8

So i normally work on external servers, but decided to set up a local environment in the form of WAMPserver on my windows 8.1 computer.
From (git bash) console, i can run lessc without a problem, but when i install Yii2, and attempt to process .less it says it can't find the command.
AssetConverter command 'lessc "C:/wamp/www/basic/web/css/site.less" "C:/wamp/www/basic/web/css/site.css" --no-color --source-map' failed with exit code 1:
STDOUT:
STDERR:
'lessc' is not recognized as an internal or external command,
operable program or batch file.
Now as far as i can tell, this should work. In fact, when i run that same command from console it works just fine. Am i missing a step here? Any help would be appreciated.
I fixed it just now.
How should you do?
Make sure you can run lessc in cmd windows.If you can't,install it with node.js Install lessc with node.js
Make sure lessc path in system path.Mine is C:\Users\l7861\AppData\Roaming\npm or you can type where lessc in cmd windows to find it.
Make sure you can see lessc path in path_info().If you can't restart your apache server.
Finally you don't need to add addassetManager in config never~~~~~
This below is a discovery process.
I just thought it is a bug on yii2 at first.So I debug it with Phpstrom.And I saw this line:path\to\vendor\yiisoft\yii2\web\AssetConverter.php 91
$command = Yii::getAlias($command);
$command = strtr($command, [
'{from}' => escapeshellarg("$basePath/$asset"),
'{to}' => escapeshellarg("$basePath/$result"),
]);
$descriptor = [
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$pipes = [];
$proc = proc_open($command, $descriptor, $pipes, $basePath);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
foreach ($pipes as $pipe) {
fclose($pipe);
}
$status = proc_close($proc);
if ($status === 0) {
Yii::trace("Converted $asset into $result:\nSTDOUT:\n$stdout\nSTDERR:\n$stderr", __METHOD__);
} elseif (YII_DEBUG) {
throw new Exception("AssetConverter command '$command' failed with exit code $status:\nSTDOUT:\n$stdout\nSTDERR:\n$stderr");
} else {
Yii::error("AssetConverter command '$command' failed with exit code $status:\nSTDOUT:\n$stdout\nSTDERR:\n$stderr", __METHOD__);
}
return $status === 0
}
Only if $status is not 0,then you got a error message.
And that usually means $command has something wrong.
When I ran to here, I could see it is 'lessc "path/to/frontend/web/less/main.less" "path/to/frontend/web/less/main.css" --no-color';
And I ran it in cmd.Then css file was created by it.
I wrote a similar code below like that function
$command='lessc "path/to/frontend/web/less/main.less" "path/to/frontend/web/less/main.css" --no-color';
$basePath="path/to/frontend/web";
$descriptor = [
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$pipes = [];
$process = proc_open($command, $descriptor, $pipes /* $cwd, $env */ );
print_r($pipes);
$stdout = stream_get_contents($pipes[1]);
echo mb_convert_encoding($stdout, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
$stderr = stream_get_contents($pipes[2]);
echo mb_convert_encoding($stderr, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
if (is_resource($process)) {
fwrite($pipes[1], '<?php print_r($_ENV); ?>');
fclose($pipes[1]);
echo stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
And ran it in browser.Then I got a error "lessc is not recognized as an internal or external command".
So I chang config file config/main.php,
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'assetManager' => [
'converter' => [
'class' => 'yii\web\AssetConverter',
'commands' => [
'less' => ['css', 'lessc {from} {to} --no-color'],
],
],
],
],
'name' => 'FavorTGD',
];
I got a same a same message.So I check out php_info(),there no lessc program in path.there there.That all you need is just restart your apache.
And delete assetManager in main.php
Ended up fixing it by changing the command to reference the lessc.cmd directly
'assetManager'=>[
'converter' => [
'class' => 'yii\web\AssetConverter',
'commands' => [
'less' => ['css', 'c:\path\to\lessc.cmd {from} {to} --no-color'],
],
],
],
Not to happy about the fix, because this means i will need to change my settings when i go 'live', but nothing else worked. I tried symlinking it into the yii directory, commands directory, etc.. but no good.

Yii2 disable asset of a vendor module

I have installed yii2-admin module, located in /vendor/mdmsoft/yii2-admin but I don't want it to load its own asset bundle. It there any way to disable this module asset bundle?
Yes, it's possible and even mentioned in official docs here. One way to do it is through application config:
return [
// ...
'components' => [
'assetManager' => [
'bundles' => [
'mdm\admin\AdminAsset' => false,
],
],
],
];
Another way - during runtime through component:
\Yii::$app->assetManager->bundles['mdm\admin\AdminAsset'] = false;

Configuring Apache with Puppet and Vagrant

I'm using Vagrant and Puppet for the first time in a project and I keep running into an issue.
I've used PuPHPet as a starting point, and I have the following snippet in my default.pp manifest:
class { 'apache': }
apache::dotconf { 'custom':
content => 'EnableSendfile Off',
}
apache::module { 'rewrite': }
apache::vhost { 'awesome.dev':
server_name => 'awesome.dev',
serveraliases => [
],
docroot => '/var/www',
port => '80',
directories => [ { path => '/var/www/', allow => 'from all', allow_override => ['All'] } ],
env_variables => [],
priority => '1',
}
When I run it, I always get the following error:
warning: Could not retrieve fact fqdn
Invalid parameter directories at /tmp/vagrant-puppet/manifests/default.pp:46 on node precise32
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
cd /tmp/vagrant-puppet/manifests && puppet apply --verbose --modulepath '/etc/puppet/modules:/tmp/vagrant-puppet/modules-0' default.pp --detailed-exitcodes || [ $? -eq 2 ]
Line 46 is the end of the apache::vhost rule. I want to set it to allow override using htaccess, but I can't see where I've gone wrong. Can anyone see what the issue is?
PuPHPet uses the Example42 Apache Puppet module, see the README file. This module doesn't have a directories parameter in the vhost resource:
https://github.com/puphpet/puphpet-apache/blob/master/manifests/vhost.pp#L100
Only the Puppet Labs Apache module has a directories parameter, but it's a different module:
https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp#L25
You can however use the directory parameter in Example42's module similarly to the example which can be found in the vhost resource:
# apache::vhost { 'my.other.site':
# docroot => '/path/to/docroot',
# directory => '/path/to',
# directory_allow_override => 'All',
# }