How to install custom module and its dependencies with composer in Drupal 8 - drupal

Hi I am trying to setup my new Drupal 8 site with composer, but I got few issues.
I tried to setup the site site by following the Guide from here and was able to setup the site successfully.
After that I tried to install a custom module which is hosted on Bitbucket and I am able to download the package using composer, but the problem is the module has some other contributed module dependency but the dependency module is not downloaded along with the custom module.
I followed the guide from here and added composer.json file to my custom module along with the dependency but after running composer require custom/custom_module only the custom module is installed but not the dependency.
My root directory composer.json file repositories section looks like this :
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "package",
"package": {
"name": "custom/custom_module",
"version": "master",
"type": "drupal-custom-module",
"source": {
"type": "git",
"url": "git#bitbucket.org:username/custom-module.git",
"reference": "master"
}
}
}
],
and the composer.json file from the custom module looks as below :
{
"name": "custom/custom_module",
"description": "This is a Custom Module with Different functionalities.",
"type": "drupal-custom-module",
"minimum-stability": "dev",
"require": {
"drupal/restui": "~1.16"
}
}
I also chaged the line "drupal/restui": "~1.16" as "drupal/restui": "^1.16" but with no success.
I even tried running composer update in the custom module directory as I was not sure whether dependencies will be installed along with custom module.
After running composer update in the custom module directory I got the following error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package drupal/restui could not be found in any version, the re may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your min imum-stability setting
see https://getcomposer.org/doc/04-schema.md#minimum-stability for more det ails.
- It's a private package and you forgot to add a custom repository to find it
Read https://getcomposer.org/doc/articles/troubleshooting.md for further commo n problems.
But on Drupal.org I can find the module with that version here
Please help me to solve the issue.

Try this:
Root composer.json section
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "vcs",
"url": "git#bitbucket.org:username/custom-module"
}
],
Module composer.json example that has two modules as dependency
{
"name": "username/custom-module",
"version": "1.2.3",
"type": "drupal-custom-module",
"description": "Custom module",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"drupal/admin_toolbar": ">=1.2",
"drupal/chosen": ">=2.6"
}
}

Related

Cannot debug R in VSCode

I created a very simple .r file insider a folder and want to debug this file using VSCode.
Here are the steps taken:
Create a new folder in desktop;
Create a .r file inside the new folder and add simple R code;
Load the new folder into VSCode and open the .r file;
Click the debug icon in VSCode, create a launch.json file and save it to the .vscode folder inside the new folder;
Click start debugging, the debug floating control pane appears but the step in/out icons are greyed out.
Here is the launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "R-Debugger",
"name": "Launch R-Workspace",
"request": "launch",
"debugMode": "workspace",
"workingDirectory": "${workspaceFolder}"
},
{
"type": "R-Debugger",
"name": "Debug R-File",
"request": "launch",
"debugMode": "file",
"workingDirectory": "${workspaceFolder}",
"file": "${file}"
},
{
"type": "R-Debugger",
"name": "Debug R-Function",
"request": "launch",
"debugMode": "function",
"workingDirectory": "${workspaceFolder}",
"file": "${file}",
"mainFunction": "main",
"allowGlobalDebugging": false
},
{
"type": "R-Debugger",
"name": "Debug R-Package",
"request": "launch",
"debugMode": "workspace",
"workingDirectory": "${workspaceFolder}",
"includePackageScopes": true,
"loadPackages": [
"."
]
},
{
"type": "R-Debugger",
"request": "attach",
"name": "Attach to R process",
"splitOverwrittenOutput": true
}
]
}
Here is the screentshot:
Why are the step in/out icons are greyed out? I simply cannot debug R file in VSCode in current state. Thank you.
The error you are getting is:
Error: '.vsc.listenForJSON' is not an exported object from 'namespace:vscDebugger'
This is a known issue caused by an older version of the R package. According to the package maintainer, the solution to this issue is,
You can run rdebugger.updateRPackage in the command palette (ctrl+shift+p) to update the R package. If that doesn't work, there are some installation instructions in the readme.
If your problem still persists after following these instructions, I would considering opening a github issue. Someone opened what appears to be a similar issue 12 days ago so it may be the package has broken on some systems after a recent update either to this package or a dependency.

How to I prevent Microsoft.Automation/automationAccounts/Compilationjobs to always run in ARM deployment?

My ARM template is below which is nested template in bigger ARM template. For some reason DSC Compilation job always run on each deployment. I expected it not be run if it was already run before. How do I control this behavior? I tried using "incrementNodeConfigurationBuild": "false" but it did not do the trick.
{
"name": "WorkerNodeDscConfiguration",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"resourceGroup": "[parameters('automationAccountRGName')]",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"resources": [
{
"apiversion": "2015-10-31",
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]",
"name": "[parameters('automationAccountName')]",
"type": "Microsoft.Automation/automationAccounts",
"properties": {
"sku": {
"name": "Basic"
}
},
"tags": {},
"resources": [
{
"name": "workernode",
"type": "configurations",
"apiVersion": "2018-01-15",
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]",
"dependsOn": [
"[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'))]"
],
"properties": {
"state": "Published",
"overwrite": "false",
"incrementNodeConfigurationBuild": "false",
"Source": {
"Version": "1.2",
"type": "uri",
"value": "[parameters('WorkerNodeDSCConfigURL')]"
}
}
},
{
"name": "[guid(resourceGroup().id, deployment().name)]",
"type": "Compilationjobs",
"apiVersion": "2018-01-15",
"tags": {},
"dependsOn": [
"[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'))]",
"[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'),'/Configurations/workernode')]"
],
"properties": {
"configuration": {
"name": "workernode"
},
"incrementNodeConfigurationBuild": "false",
"parameters": {
"WebServerContentURL": "[parameters('WebServerContentURL')]"
}
}
}
]
}
]
}
}
}
In short, AFAIK you should be able to control this behaviour with 'condition'.
To explain it in detail, the DSC compilation jobs resource always run on each deployment because when we use the DSC compilation jobs resource (i.e., Microsoft.Automation/automationAccounts/compilationjobs) in the ARM template, IMHO what it does in the behind is, basically clicks on 'Compile' button of the DSC configuration.
If you click on that 'Compile' button, the compilation of job happens for sure even if it already compiled the job. You may check the same part manually as well.
So AFAIK that was the reason for compilation job always running on each deployment.
What you could do is, update your ARM template with 'condition' (For more information, refer https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-resources#condition and https://learn.microsoft.com/en-us/azure/architecture/building-blocks/extending-templates/conditional-deploy) and then wrap your template with below sample piece of PowerShell code that would determine if the Compilation of job for particular DSC configuration is done already and then deploy the template by passing inline parameter value or by updating condition parameter in parameters template file with new or existing value accordingly. (For more information, refer https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy#pass-parameter-values)
$DscCompilationJob = Get-AzAutomationDscCompilationJob -AutomationAccountName AUTOMATIONACCOUNTNAME -ResourceGroupName RESOURCEGROUPNAME|Sort-Object -Descending -Property CreationTime|Select -First 1| Select Status
$DscCompilationJobStatus = $DscCompilationJob.Status
if ($DscCompilationJobStatus -ne "Completed"){
$DscCompilationJobStatusInlineParameter = "new"
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName testgroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -exampleString $DscCompilationJobStatusInlineParameter
#or update condition parameter in parameters template file with new value accordingly and use below command to deploy the template
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -TemplateParameterFile TEMPLATEFILEPATH\demotemplate.parameters.json
}else{
$DscCompilationJobStatusInlineParameter = "existing"
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName testgroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -exampleString $DscCompilationJobStatusInlineParameter
#or update condition parameter in parameters template file with existing value accordingly and use below command to deploy the template
New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -TemplateParameterFile TEMPLATEFILEPATH\demotemplate.parameters.json
}
And regarding incrementNodeConfigurationBuild property, IMHO this property is just with regards to creation of a new build version of Node Configuration is required or not i.e., when incremental node configuration build is set to false, it does not override the earlier existing Node Configuration by creating a new Node Configuration with the name CONFIGNAME[<2>] (the version number is incremented based on the existing version number already present).
Hope this helps!! Cheers!! :)

Query regarding Artifactory APIs

I am trying to integrate with Artifactory using rest APIs and to do that need to be able to do the following:
Give a filter list of repositories based on tool type e.g I will like to only get repositories which are either nuget or npm based. I tried using https://user.jfrog.io/user/api/repositories but it doesn't return the type of repository so i cannot filter the list. I see that https://user.jfrog.io/user/api/storageinfo returns repositoriesSummaryList which includes the package type of repositories. Is it ok to use this APIs for getting the list of repositories and filtering?
Given a repository I want to get list of packages in that repository. The only way i could find out for this was making a POST call to https://user.jfrog.io/user/api/search/aql with the body
items.find(
{
"repo":{"$eq":"myawesome-remotenugetrepo-cache"}
}
)
Is there any way to get this information using a GET call instead of POST?
In Artifactory different versions of same package are treated as different packages For Example: For the Query in 2 the result is something like this:
[
{
"repo": "myawesome-remotenugetrepo-cache",
"path": ".",
"name": "bootstrap.3.3.2.nupkg",
"type": "file",
"size": 264693,
"created": "2016-05-27T16:07:12.138Z",
"created_by": "admin",
"modified": "2015-12-03T12:57:47.000Z",
"modified_by": "admin",
"updated": "2016-05-27T16:07:12.166Z"
},
{
"repo": "myawesome-remotenugetrepo-cache",
"path": ".",
"name": "bootstrap.3.3.6.nupkg",
"type": "file",
"size": 290372,
"created": "2016-05-27T10:55:47.576Z",
"created_by": "admin",
"modified": "2015-12-03T12:57:48.000Z",
"modified_by": "admin",
"updated": "2016-05-27T10:55:47.613Z"
},
{
"repo": "myawesome-remotenugetrepo-cache",
"path": ".",
"name": "jQuery.1.9.1.nupkg",
"type": "file",
"size": 240271,
"created": "2016-05-27T10:55:43.895Z",
"created_by": "admin",
"modified": "2015-12-07T15:58:51.000Z",
"modified_by": "admin",
"updated": "2016-05-27T10:55:43.930Z"
}
]
As you can see the result includes entries for both versions of bootstrap 3.3.2 and 3.3.6. What I hoped was that the list of packages will just include bootstrap and jQuery, Is there anyway to get this list?
Also give the package bootstrap is there any way to query for different versions of it?
Yes.
You can use the Folder Info GET request.
There are two questions there :)
Not really. You'll probably have to write a simple script to group by the common part of the artifact name.
You can get information about the version of the artifact once you have a repository layout set up. Then you can use queries like Artifact Version Search.

use PHPExcel with composer and Symfony2.2

I found this on SO: How to use PHPExcel correctly with Symfony 2
This works, but I want to use it with composer.
The first part I already solved: to load PHPExcel for a special tag (the last stable release)
I don't find out how to fetch a tag with this syntax:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/umpirsky/SyliusAssortmentBundle"
}
]
So I use the Package notation:
I found out, the reference should be the tag name on github.
And the version cannot be the same value (PHPExcel_1.7.8). Seems that alphabetical characters are not allowed, so it's only the version as a number (1.7.8)
"repositories": [{
"type": "package",
"package": {
"name": "PHPOffice/PHPExcel",
"version": "1.7.8",
"source": {
"url": "https://github.com/PHPOffice/PHPExcel.git",
"type": "git",
"reference": "PHPExcel_1.7.8"
}
}
}]
The next step I didn't solve. I tried out every combination for the autoloading: psr-0, classmap, different paths, relative to project/vendor/phpexcel, update composer everytime, but nothing worked.
It only works, if I put this line
$loader->add('PHPExcel', __DIR__.'/../vendor/PHPOffice/PHPExcel/Classes');
into the app/autoload.php. I found out, that the first string (PHPExcel) can also be an empty string: ''.
Is there a differnece if I use PHPExcel or ''?
So my primary question is, how can I avoid to write this line into the autoload.php, put the equivalent commands into my project's composer.json?
Regarding your primary question, the problem is that once the package is installed, if you update the definition and add autoload stuff, then running composer update will not change anything. Composer still has the old package that was already installed in its "cache", so it uses that to generate the autoload and that fails.
To resolve this you should remove the vendor/PHPOffice/PHPExcel directly and run composer update, which will reinstall it with the latest information from your composer.json, including autoload, etc. You should specify autoloading as such:
"repositories": [{
"type": "package",
"package": {
"name": "PHPOffice/PHPExcel",
"version": "1.8.0",
"source": {
"url": "https://github.com/PHPOffice/PHPExcel.git",
"type": "git",
"reference": "1.8.0"
},
"autoload": {
"psr-0": {
"PHPExcel": "Classes/"
}
}
}
}],
"require": {
"PHPOffice/PHPExcel": "1.8.*",
...
Regarding the secondary question and '' vs 'PHPExcel': '' just says that any namespace can be found in this directory. That means the autoloader will always scan this directory to find classes, which is convenient but slower than mapping namespaces to directories explicitly. So both work, but the more specific form is preferred, especially in packages you publish publicly.

Wrap PHPWord on bundle

I just want to use PHPWord for Symfony 2. But Im new on Symfony 2.
I paste PHPWord source into my util folder bundle but there is an error loading autoloader class from PHPWord...
Question is simple, How can I "wrap" code (in this case PHPWord) in to bundle? or someway I can use it.
Any solution?
Thanks for answering, that gives me some light. Altough, This doen't work for me.
I download composer.phar and I edit my composer.json as you say: adding in my require region "phpword/phpword": "0.6.2" and creating new repository phpword...
Doesn't work, I run "php composer.phar" command but It doesn't download anything...
Any tutorial or tip to make this work?
Thank you
composer require phpoffice/phpword dev-master did the work for me.
It should download and place install PhpOffice\PHPWord under the vendor folder in your Symfony2 installation (besides modifying your composer.json automatically).
In the controller you are about to use PhpWord:
use PhpOffice\PhpWord\PhpWord;
And inside the action, you can create a new instance as follows:
$doc = new PhpWord();
You shouldn't be copying the source code yourself. Use composer to install PHPWord.
Since PHPWord doesn't use composer (yet), you'll need to define a repository in your composer.json:
{
"require": {
"phpword/phpword": "0.6.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "0.6.2",
"dist": {
"url": "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=phpword&DownloadId=138035&FileTime=129545976016270000&Build=19692",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
Than you'll be able to use PHPWord in your Symfony project (any PHP project in fact):
$word = new PHPWord();
$writer = new PHPWord_Writer_Word2007($word);
$writer->save('test.doc');
Update: I just realized the URL to download changes with time. It'd be better to replace it with something that doesn't change (if possible, otherwise host it somewhere yourself).
As the URL changes, you can use the github repository if you've no problem with the dev version :
{
"require": {
"phpword/phpword": "dev"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "dev",
"dist": {
"url": "https://github.com/PHPOffice/PHPWord/archive/develop.zip",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
You can use this simple bundle as wrapper for PhpWord:
https://packagist.org/packages/ggggino/wordbundle

Resources