1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||||||
5 | * @copyright Metaways Infosystems GmbH, 2014 |
||||||
6 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||||||
7 | */ |
||||||
8 | |||||||
9 | |||||||
10 | namespace Aimeos\MW\Setup\Task; |
||||||
11 | |||||||
12 | |||||||
13 | /** |
||||||
14 | * Adds demo records to catalog tables. |
||||||
15 | */ |
||||||
16 | class DemoAddCatalogData extends \Aimeos\MW\Setup\Task\MShopAddDataAbstract |
||||||
17 | { |
||||||
18 | /** |
||||||
19 | * Returns the list of task names which this task depends on. |
||||||
20 | * |
||||||
21 | * @return string[] List of task names |
||||||
22 | */ |
||||||
23 | public function getPreDependencies() |
||||||
24 | { |
||||||
25 | return array( 'DemoAddProductData' ); |
||||||
26 | } |
||||||
27 | |||||||
28 | |||||||
29 | /** |
||||||
30 | * Returns the list of task names which depends on this task. |
||||||
31 | * |
||||||
32 | * @return string[] List of task names |
||||||
33 | */ |
||||||
34 | public function getPostDependencies() |
||||||
35 | { |
||||||
36 | return array( 'DemoRebuildIndex' ); |
||||||
37 | } |
||||||
38 | |||||||
39 | |||||||
40 | /** |
||||||
41 | * Insert catalog nodes and relations. |
||||||
42 | */ |
||||||
43 | public function migrate() |
||||||
44 | { |
||||||
45 | $this->msg( 'Processing catalog demo data', 0 ); |
||||||
46 | |||||||
47 | $context = $this->getContext(); |
||||||
48 | $value = $context->getConfig()->get( 'setup/default/demo', '' ); |
||||||
49 | |||||||
50 | if( $value === '' ) |
||||||
51 | { |
||||||
52 | $this->status( 'OK' ); |
||||||
53 | return; |
||||||
54 | } |
||||||
55 | |||||||
56 | |||||||
57 | $item = null; |
||||||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||||||
58 | $manager = \Aimeos\MShop::create( $context, 'catalog' ); |
||||||
59 | |||||||
60 | try |
||||||
61 | { |
||||||
62 | // Don't delete the catalog node because users are likely use it for production |
||||||
63 | $item = $manager->getTree( null, [], \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
||||||
64 | |||||||
65 | $this->removeItems( $item->getId(), 'catalog/lists', 'catalog', 'media' ); |
||||||
66 | $this->removeItems( $item->getId(), 'catalog/lists', 'catalog', 'text' ); |
||||||
67 | $this->removeListItems( $item->getId(), 'catalog/lists', 'product' ); |
||||||
68 | } |
||||||
69 | catch( \Exception $e ) {; } // If no root node was already inserted into the database |
||||||
70 | |||||||
71 | |||||||
72 | if( $value === '1' ) |
||||||
73 | { |
||||||
74 | $ds = DIRECTORY_SEPARATOR; |
||||||
75 | $path = __DIR__ . $ds . 'data' . $ds . 'demo-catalog.php'; |
||||||
76 | |||||||
77 | if( ( $data = include( $path ) ) == false ) { |
||||||
78 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for catalog domain', $path ) ); |
||||||
79 | } |
||||||
80 | |||||||
81 | if( $item === null ) |
||||||
82 | { |
||||||
83 | $item = $manager->createItem(); |
||||||
84 | $item->setCode( $data['code'] ); |
||||||
85 | $item->setLabel( $data['label'] ); |
||||||
86 | $item->setConfig( $data['config'] ); |
||||||
0 ignored issues
–
show
The method
setConfig() does not exist on Aimeos\MShop\Attribute\Item\Iface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
87 | $item->setStatus( $data['status'] ); |
||||||
88 | |||||||
89 | $manager->insertItem( $item ); |
||||||
90 | } |
||||||
91 | |||||||
92 | |||||||
93 | if( isset( $data['media'] ) ) { |
||||||
94 | $this->addMedia( $item->getId(), $data['media'], 'catalog' ); |
||||||
95 | } |
||||||
96 | |||||||
97 | if( isset( $data['product'] ) ) { |
||||||
98 | $this->addProducts( $item->getId(), $data['product'], 'catalog' ); |
||||||
99 | } |
||||||
100 | |||||||
101 | if( isset( $data['text'] ) ) { |
||||||
102 | $this->addTexts( $item->getId(), $data['text'], 'catalog' ); |
||||||
103 | } |
||||||
104 | |||||||
105 | $this->status( 'added' ); |
||||||
106 | } |
||||||
107 | else |
||||||
108 | { |
||||||
109 | $this->status( 'removed' ); |
||||||
110 | } |
||||||
111 | } |
||||||
112 | } |
||||||
113 |