Skip to content

Commit

Permalink
Add default codes to tables
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Jan 20, 2016
1 parent ae1fa3a commit 30cb387
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 83 deletions.
@@ -1,7 +1,6 @@
<?php

/**
* @copyright Metaways Infosystems GmbH, 2012
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015
*/
Expand All @@ -11,9 +10,9 @@


/**
* Adds product stock test data.
* Adds default codes to tables
*/
class MShopAddWarehouseData extends \Aimeos\MW\Setup\Task\Base
class MShopAddCodeData extends \Aimeos\MW\Setup\Task\Base
{

/**
Expand Down Expand Up @@ -49,7 +48,7 @@ protected function mysql()


/**
* Adds product stock test data.
* Adds the default codes
*/
protected function process()
{
Expand All @@ -58,36 +57,43 @@ protected function process()
throw new \Aimeos\MW\Setup\Exception( sprintf( 'Additionally provided object is not of type "%1$s"', $iface ) );
}

$this->msg( 'Adding warehouse data', 0 );
$site = $this->additional->getLocale()->getSite()->getCode();
$this->msg( sprintf( 'Adding default code data for site "%1$s"', $site ), 0 ); $this->status( '' );

$ds = DIRECTORY_SEPARATOR;
$path = __DIR__ . $ds . 'default' . $ds . 'data' . $ds . 'warehouse.php';
$path = __DIR__ . $ds . 'default' . $ds . 'data' . $ds . 'code.php';

if( ( $data = include( $path ) ) == false ) {
throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for product stock domain', $path ) );
throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for default codes', $path ) );
}

$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->additional );
$warehouseManager = $manager->getSubManager( 'stock' )->getSubManager( 'warehouse' );
foreach( $data as $domain => $datasets )
{
$this->msg( sprintf( 'Checking "%1$s" codes', $domain ), 1 );

$num = $total = 0;
$item = $warehouseManager->createItem();
$domainManager = \Aimeos\MShop\Factory::createManager( $this->additional, $domain );
$type = $domainManager->createItem();
$num = $total = 0;

foreach( $data['warehouse'] as $key => $dataset )
{
$total++;
foreach( $datasets as $dataset )
{
$total++;

$item->setId( null );
$item->setCode( $dataset['code'] );
$item->setLabel( $dataset['label'] );
$item->setStatus( $dataset['status'] );
$type->setId( null );
$type->setCode( $dataset['code'] );
$type->setLabel( $dataset['label'] );

try {
$warehouseManager->saveItem( $item );
$num++;
} catch( \Aimeos\MW\DB\Exception $e ) { ; } // if warehouse was already available
}
if( isset( $dataset['status'] ) ) {
$type->setStatus( $dataset['status'] );
}

$this->status( $num > 0 ? $num . '/' . $total : 'OK' );
try {
$domainManager->saveItem( $type );
$num++;
} catch( \Exception $e ) {; } // if type was already available
}

$this->status( $num > 0 ? $num . '/' . $total : 'OK' );
}
}
}
2 changes: 1 addition & 1 deletion lib/mshoplib/setup/default/DemoAddCustomerData.php
Expand Up @@ -22,7 +22,7 @@ class DemoAddCustomerData extends \Aimeos\MW\Setup\Task\MShopAddDataAbstract
*/
public function getPreDependencies()
{
return array( 'MShopAddTypeDataDefault' );
return array( 'MShopAddTypeDataDefault', 'MShopAddCodeDataDefault' );
}


Expand Down
2 changes: 1 addition & 1 deletion lib/mshoplib/setup/default/DemoAddProductData.php
Expand Up @@ -22,7 +22,7 @@ class DemoAddProductData extends \Aimeos\MW\Setup\Task\MShopAddDataAbstract
*/
public function getPreDependencies()
{
return array( 'MShopAddTypeDataDefault', 'MShopAddWarehouseDataDefault' );
return array( 'MShopAddTypeDataDefault', 'MShopAddCodeDataDefault' );
}


Expand Down
@@ -1,7 +1,6 @@
<?php

/**
* @copyright Metaways Infosystems GmbH, 201
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015
*/
Expand All @@ -11,12 +10,12 @@


/**
* Adds default records to plugin table.
* Adds code records to the tables
*/
class MShopAddWarehouseDataDefault extends \Aimeos\MW\Setup\Task\MShopAddWarehouseData
class MShopAddCodeDataDefault extends \Aimeos\MW\Setup\Task\MShopAddCodeData
{
/**
* Returns the list of task names which this task depends on.
* Returns the list of task names which this task depends on
*
* @return string[] List of task names
*/
Expand All @@ -27,18 +26,18 @@ public function getPreDependencies()


/**
* Returns the list of task names which depends on this task.
* Returns the list of task names which depends on this task
*
* @return string[] List of task names
*/
public function getPostDependencies()
{
return array( 'MShopAddWarehouseData' );
return array();
}


/**
* Executes the task for MySQL databases.
* Executes the task for MySQL databases
*/
protected function mysql()
{
Expand Down
@@ -1,12 +1,15 @@
<?php
/**
* @copyright Metaways Infosystems GmbH, 2012
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015
*/

return array(
'warehouse' => array(
'customer/group' => array(
'admin' => array( 'code' => 'admin', 'label' => 'Administrator' ),
),

'product/stock/warehouse' => array(
'default' => array( 'code' => 'default', 'label' => 'Standard', 'status' => 1 ),
),
);
46 changes: 46 additions & 0 deletions lib/mshoplib/setup/unitperf/MShopAddCodeDataUnitperf.php
@@ -0,0 +1,46 @@
<?php

/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015-2016
*/


namespace Aimeos\MW\Setup\Task;


/**
* Adds default codes to tables
*/
class MShopAddCodeDataUnitperf extends \Aimeos\MW\Setup\Task\MShopAddCodeData
{
/**
* Returns the list of task names which this task depends on
*
* @return string[] List of task names
*/
public function getPreDependencies()
{
return array( 'MShopSetLocale' );
}


/**
* Returns the list of task names which depends on this task
*
* @return string[] List of task names
*/
public function getPostDependencies()
{
return array();
}


/**
* Executes the task for MySQL databases
*/
protected function mysql()
{
$this->process();
}
}
47 changes: 0 additions & 47 deletions lib/mshoplib/setup/unitperf/MShopAddWarehouseDataUnitperf.php

This file was deleted.

2 changes: 1 addition & 1 deletion lib/mshoplib/setup/unitperf/ProductAddBasePerfData.php
Expand Up @@ -36,7 +36,7 @@ public function __construct( \Aimeos\MW\Setup\DBSchema\Iface $schema, \Aimeos\MW
*/
public function getPreDependencies()
{
return array( 'MShopAddTypeDataUnitperf' );
return array( 'MShopAddTypeDataUnitperf', 'MShopAddCodeDataUnitperf' );
}


Expand Down

0 comments on commit 30cb387

Please sign in to comment.