Skip to content

Commit

Permalink
Implement cleanup method in site manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Feb 3, 2018
1 parent c10b69d commit d5b5b72
Showing 1 changed file with 71 additions and 56 deletions.
127 changes: 71 additions & 56 deletions lib/mshoplib/src/MShop/Locale/Manager/Site/Standard.php
Expand Up @@ -134,6 +134,75 @@ public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
}


/**
* Removes old entries from the storage.
*
* @param integer[] $siteids List of IDs for sites whose entries should be deleted
*/
public function cleanup( array $siteids )
{
$context = $this->getContext();
$config = $context->getConfig();

/** mshop/locale/manager/site/cleanup/shop/domains
* List of madmin domains names whose items referring to the same site should be deleted as well
*
* As items for each domain can be stored in a separate database, the
* site manager needs a list of domain names used to connect to the
* correct database and to remove all items that belong the the deleted
* site.
*
* For each domain the cleanup will be done by the corresponding MShop
* manager. To keep records for old sites in the database even if the
* site was already deleted, you can configure a new list with the
* domains removed you would like to keep, e.g. the "order" domain to
* keep all orders ever placed.
*
* @param array List of domain names in lower case
* @since 2014.03
* @category Developer
* @see mshop/locale/manager/site/cleanup/admin/domains
*/
$path = 'mshop/locale/manager/site/cleanup/shop/domains';
$default = array(
'attribute', 'catalog', 'coupon', 'customer', 'index',
'media', 'order', 'plugin', 'price', 'product', 'tag',
'service', 'subscription', 'supplier', 'text'
);

foreach( $config->get( $path, $default ) as $domain ) {
echo 'domain: ' . $domain . PHP_EOL;
\Aimeos\MShop\Factory::createManager( $context, $domain )->cleanup( $siteids );
}

/** mshop/locale/manager/site/cleanup/admin/domains
* List of mshop domains names whose items referring to the same site should be deleted as well
*
* As items for each domain can be stored in a separate database, the
* site manager needs a list of domain names used to connect to the
* correct database and to remove all items that belong the the deleted
* site.
*
* For each domain the cleanup will be done by the corresponding MAdmin
* manager. To keep records for old sites in the database even if the
* site was already deleted, you can configure a new list with the
* domains removed you would like to keep, e.g. the "log" domain to
* keep all log entries ever written.
*
* @param array List of domain names in lower case
* @since 2014.03
* @category Developer
* @see mshop/locale/manager/site/cleanup/shop/domains
*/
$path = 'mshop/locale/manager/site/cleanup/admin/domains';
$default = array( 'job', 'log', 'cache' );

foreach( $config->get( $path, $default ) as $domain ) {
\Aimeos\MAdmin\Factory::createManager( $context, $domain )->cleanup( $siteids );
}
}


/**
* Creates a new site object.
*
Expand Down Expand Up @@ -245,6 +314,8 @@ public function deleteItems( array $ids )
$context = $this->getContext();
$config = $context->getConfig();

$this->cleanup( $ids );

/** mshop/locale/manager/site/standard/delete/mysql
* Deletes the items matched by the given IDs from the database
*
Expand Down Expand Up @@ -277,62 +348,6 @@ public function deleteItems( array $ids )
*/
$path = 'mshop/locale/manager/site/standard/delete';
$this->deleteItemsBase( $ids, $path, false );

/** mshop/locale/manager/site/cleanup/shop/domains
* List of madmin domains names whose items referring to the same site should be deleted as well
*
* As items for each domain can be stored in a separate database, the
* site manager needs a list of domain names used to connect to the
* correct database and to remove all items that belong the the deleted
* site.
*
* For each domain the cleanup will be done by the corresponding MShop
* manager. To keep records for old sites in the database even if the
* site was already deleted, you can configure a new list with the
* domains removed you would like to keep, e.g. the "order" domain to
* keep all orders ever placed.
*
* @param array List of domain names in lower case
* @since 2014.03
* @category Developer
* @see mshop/locale/manager/site/cleanup/admin/domains
*/
$path = 'mshop/locale/manager/site/cleanup/shop/domains';
$default = array(
'attribute', 'catalog', 'coupon', 'customer', 'index',
'media', 'order', 'plugin', 'price', 'product', 'tag',
'service', 'supplier', 'text'
);

foreach( $config->get( $path, $default ) as $domain ) {
\Aimeos\MShop\Factory::createManager( $context, $domain )->cleanup( $ids );
}

/** mshop/locale/manager/site/cleanup/admin/domains
* List of mshop domains names whose items referring to the same site should be deleted as well
*
* As items for each domain can be stored in a separate database, the
* site manager needs a list of domain names used to connect to the
* correct database and to remove all items that belong the the deleted
* site.
*
* For each domain the cleanup will be done by the corresponding MAdmin
* manager. To keep records for old sites in the database even if the
* site was already deleted, you can configure a new list with the
* domains removed you would like to keep, e.g. the "log" domain to
* keep all log entries ever written.
*
* @param array List of domain names in lower case
* @since 2014.03
* @category Developer
* @see mshop/locale/manager/site/cleanup/shop/domains
*/
$path = 'mshop/locale/manager/site/cleanup/admin/domains';
$default = array( 'job', 'log', 'cache' );

foreach( $config->get( $path, $default ) as $domain ) {
\Aimeos\MAdmin\Factory::createManager( $context, $domain )->cleanup( $ids );
}
}


Expand Down

0 comments on commit d5b5b72

Please sign in to comment.