New site creating commands works in terminal but not from shell_exec() PHP command

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
dinindu98
Posts: 6
Joined: 24 Dec 2020, 17:54

New site creating commands works in terminal but not from shell_exec() PHP command

Post by dinindu98 » 24 Dec 2020, 18:12

New site creating commands works in terminal but not from shell_exec() PHP command
command*
$output = shell_exec("cd .. && php artisan aimeos:setup $companyName ");

PHP version 7.3.1
laravel 7
OS - windows

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by aimeos » 27 Dec 2020, 17:53

You can use the code for the database setup directly instead of using shell_exec():
https://github.com/aimeos/aimeos-larave ... hp#L60-L72
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

dinindu98
Posts: 6
Joined: 24 Dec 2020, 17:54

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by dinindu98 » 01 Jan 2021, 10:54

can you mention the code example for that create a new site with the default attributes under the above situation

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by aimeos » 02 Jan 2021, 15:42

Code: Select all

	$site = '<your new site code>';
	$ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' );
	$config = $ctx->getConfig()->set( 'setup/site', $site );
	$dbconfig = $conf->get( 'resource', [] );

	foreach( $dbconfig as $rname => $dbconf )
	{
		if( strncmp( $rname, 'db', 2 ) !== 0 ) {
			unset( $dbconfig[$rname] );
		} else {
			$conf->set( 'resource/' . $rname . '/limit', 5 );
		}
	}

	$taskPaths = $this->getLaravel()->make( 'aimeos' )->get()->getSetupPaths( 'default' );
	$manager = new \Aimeos\MW\Setup\Manager\Multiple( $ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx );
	$manager->migrate( $task );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

dinindu98
Posts: 6
Joined: 24 Dec 2020, 17:54

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by dinindu98 » 05 Jan 2021, 03:46

Code: Select all

                $site =  $this->argument( 'site' );
		$ctx = $this->getLaravel()->make( 'aimeos.context' )->get( false, 'command' );
		$config = $ctx->getConfig()->set( 'setup/site', $site );
		$dbconfig = $conf->get( 'resource', [] );

		foreach( $dbconfig as $rname => $dbconf )
		{
			if( strncmp( $rname, 'db', 2 ) !== 0 ) {
				unset( $dbconfig[$rname] );
			} else {
				$conf->set( 'resource/' . $rname . '/limit', 5 );
			}
		}

		$taskPaths = $this->getLaravel()->make( 'aimeos' )->get()->getSetupPaths( 'default' );
		$manager = new \Aimeos\MW\Setup\Manager\Multiple( $ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx );
		$manager->migrate( $task );
I added the code like this, but newly created sites still don't contain attributes of the default site.
Last edited by dinindu98 on 05 Jan 2021, 05:08, edited 1 time in total.

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by aimeos » 06 Jan 2021, 08:13

What do you mean? What are "attributes of the default site"?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

dinindu98
Posts: 6
Joined: 24 Dec 2020, 17:54

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by dinindu98 » 11 Jan 2021, 03:39

In the admin panel, there is tab called types in that tab contain the attribute, catalog lists, media, plugins, and lot more... and each table contain their own attributes [ex:- Domain:media, code:default, label:Standard].


php artisan aimeos:setup <new site code>

when I create a new site using this command, the new site is generated with those attributes which are in the default site that I mentioned above. but I want to generate a new site with those attributes in a single button click. to achieve that goal I tried running this shell command

$output = shell_exec("cd .. && php artisan aimeos:setup $companyName ");

hopefully, the site is generated with attributes but it didn't work and shows error 404 not found.
I don't know the easiest way to achieve this.

User avatar
aimeos
Administrator
Posts: 7871
Joined: 01 Jan 1970, 00:00

Re: New site creating commands works in terminal but not from shell_exec() PHP command

Post by aimeos » 13 Jan 2021, 09:12

It should work because of this line:

Code: Select all

$taskPaths = $this->getLaravel()->make( 'aimeos' )->get()->getSetupPaths( 'default' );
It uses the setup tasks for "default" which also creates the types.

The latest Aimeos distribution includes seller registration out of the box and you can use this code as reference:
https://github.com/aimeos/aimeos/blob/m ... er.php#L75
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply