Aimeos Laravel Package - How to execute Setup tasks

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!
mohal_04
Advanced
Posts: 108
Joined: 27 Mar 2018, 05:59

Aimeos Laravel Package - How to execute Setup tasks

Post by mohal_04 » 29 Mar 2018, 10:43

Laravel: 5.6
Aimeos: 2017.x
PHP: 7.x
Environment: Linux

Hi,

I need to add additional field in "mshop_price" table. The field name is "productioncost." So, I studied following link:

https://aimeos.org/docs/Developers/Library/Setup_tasks

and did what is asked. I created "price.php" file in "./ext/myextension/lib/custom/setup/default/schema" directory. Below is the code of "price.php."

https://aimeos.org/docs/Developers/Libr ... ema_update

Code: Select all

return array(
	'table' => array(
		'mshop_price' => function ( \Doctrine\DBAL\Schema\Schema $schema ) {

			// $table = $schema->createTable( 'mshop_price' );
			$table = $schema->getTable( 'mshop_price' );

			$table->addColumn(  'productioncost', 'decimal', array( 'precision' => 12, 'scale' => 2 ) );

			$table->addIndex( array( 'siteid', 'domain', 'productioncost' ), 'idx_mspri_sid_dom_productioncost' );

			return $schema;
		}
	)
);
Then I created a Basic Setup Task after reading the following URL:

https://aimeos.org/docs/Developers/Libr ... sks/Basics

I created "PriceAddProductionCost.php" file inside "./ext/myextension/lib/custom/setup" directory. Below is the code:

Code: Select all

namespace Aimeos\MW\Setup\Task;
 
class PriceAddProductionCost extends \Aimeos\MW\Setup\Task\Base
{
	private $mysql = array(
		'ALTER TABLE "mshop_price" ADD "productioncost" DECIMAL(12,2) NOT NULL AFTER "value"'
	);
	/**
	 * Returns the list of task names which this task depends on.
	 *
	 * @return string[] List of task names
	 */
	public function getPreDependencies()
	{
		return array( 'TablesCreateMShop', 'MShopAddLocaleData' );
	}
 
	/**
	 * Returns the list of task names which depends on this task.
	 *
	 * @return string[] List of task names
	 */
	public function getPostDependencies()
	{
		return [];
	}
 
	/**
	 * Updates the schema and migrates the data
	 */
	public function migrate()
	{
	}
 
	/**
	 * Undo all schema changes and migrate data back
	*/
	public function rollback()
	{
	}
 
	/**
	 * Cleans up old data required for roll back
	*/
	public function clean()
	{
	}
}
Now, I have three questions.

1. Is Setup file "PriceAddProductionCost.php" necessary to modify table?
2. If Setup file is necessary then kindly guide me if my created file "PriceAddProductionCost.php" is OK?
3. And last question, how to execute Setup file?

Please, reply ASAP!

Thanks!

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

Re: Aimeos Laravel Package - How to execute Setup tasks

Post by aimeos » 29 Mar 2018, 11:17

No, you don't need the "PriceAddProductionCost.php" file because it's only necessary if you need data migration. Schema changes are made depending on your price.php schema file by the TablesCreateMShop setup task.

You have to run "php artisan aimeos:setup" to update your database.

We are all volunteers helping others for free besides working on our own projects. If you need support within defined reaction time, please ask the Aimeos company for help: https://aimeos.com/support/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

mohal_04
Advanced
Posts: 108
Joined: 27 Mar 2018, 05:59

Re: Aimeos Laravel Package - How to execute Setup tasks

Post by mohal_04 » 30 Mar 2018, 06:59

aimeos wrote:No, you don't need the "PriceAddProductionCost.php" file because it's only necessary if you need data migration. Schema changes are made depending on your price.php schema file by the TablesCreateMShop setup task.

You have to run "php artisan aimeos:setup" to update your database.

We are all volunteers helping others for free besides working on our own projects. If you need support within defined reaction time, please ask the Aimeos company for help: https://aimeos.com/support/
Thank you so much! I really appreciate your efforts.

Post Reply