|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Setup\Task; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Adds ezPublish customer test data |
|
14
|
|
|
*/ |
|
15
|
|
|
class CustomerAddEzpublishTestData extends \Aimeos\MW\Setup\Task\CustomerAddTestData |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Returns the list of task names which this task depends on. |
|
19
|
|
|
* |
|
20
|
|
|
* @return string[] List of task names |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getPreDependencies() |
|
23
|
|
|
{ |
|
24
|
|
|
return array( 'TablesCreateEzpublish', 'EzuserAddAddress', 'MShopSetLocale', 'MediaAddTestData' ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Adds attribute test data. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function migrate() |
|
32
|
|
|
{ |
|
33
|
|
|
$iface = '\\Aimeos\\MShop\\Context\\Item\\Iface'; |
|
34
|
|
|
if( !( $this->additional instanceof $iface ) ) { |
|
35
|
|
|
throw new \Aimeos\MW\Setup\Exception( sprintf( 'Additionally provided object is not of type "%1$s"', $iface ) ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$context = $this->getEzContext( $this->additional ); |
|
39
|
|
|
|
|
40
|
|
|
$this->msg( 'Adding ezPublish customer test data', 0 ); |
|
41
|
|
|
|
|
42
|
|
|
$parentIds = array(); |
|
43
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
44
|
|
|
$context->setEditor( 'ai-ezpublish:unittest' ); |
|
45
|
|
|
$path = __DIR__ . $ds . 'data' . $ds . 'customer.php'; |
|
46
|
|
|
|
|
47
|
|
|
if( ( $testdata = include( $path ) ) === false ){ |
|
48
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for customer domain', $path ) ); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$customerManager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $context, 'Ezpublish' ); |
|
53
|
|
|
$customerAddressManager = $customerManager->getSubManager( 'address', 'Ezpublish' ); |
|
54
|
|
|
|
|
55
|
|
|
$search = $customerManager->createSearch(); |
|
56
|
|
|
$search->setConditions( $search->compare( '==', 'customer.code', array( 'UTC001', 'UTC002', 'UTC003' ) ) ); |
|
57
|
|
|
$items = $customerManager->searchItems( $search ); |
|
58
|
|
|
|
|
59
|
|
|
$this->conn->begin(); |
|
60
|
|
|
|
|
61
|
|
|
$customerManager->deleteItems( array_keys( $items ) ); |
|
62
|
|
|
$parentIds = $this->addCustomerData( $testdata, $customerManager, $customerAddressManager->createItem() ); |
|
63
|
|
|
$this->addCustomerAddressData( $testdata, $customerAddressManager, $parentIds ); |
|
64
|
|
|
|
|
65
|
|
|
$this->conn->commit(); |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$this->status( 'done' ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns the Ezpublish context |
|
74
|
|
|
* |
|
75
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
|
76
|
|
|
* @return \Aimeos\MShop\Context\Item\Ezpublish Ezpublish context object |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function getEzContext( \Aimeos\MShop\Context\Item\Iface $context ) |
|
79
|
|
|
{ |
|
80
|
|
|
$class = '\Aimeos\MShop\Context\Item\Ezpublish'; |
|
81
|
|
|
if( is_a( $context, $class ) ) { |
|
82
|
|
|
return $context; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$ezContext = new \Aimeos\MShop\Context\Item\Ezpublish(); |
|
86
|
|
|
$ezContext->setDatabaseManager( clone $context->getDatabaseManager() ); |
|
87
|
|
|
$ezContext->setSession( clone $context->getSession() ); |
|
88
|
|
|
$ezContext->setLogger( clone $context->getLogger() ); |
|
89
|
|
|
$ezContext->setLocale( clone $context->getLocale() ); |
|
90
|
|
|
$ezContext->setConfig( clone $context->getConfig() ); |
|
91
|
|
|
$ezContext->setCache( clone $context->getCache() ); |
|
92
|
|
|
|
|
93
|
|
|
$task = $this; |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
View Code Duplication |
$ezContext->setEzUser( function( $code, $email, $password ) use ( $context ) { |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$id = mt_rand( -0x7fffffff,-1 ); |
|
98
|
|
|
$dbm = $context->getDatabaseManager(); |
|
99
|
|
|
$dbconf = $context->getConfig()->get( 'resource/db-customer' ); |
|
100
|
|
|
$dbname = ( $dbconf ? 'db-customer' : 'db' ); |
|
101
|
|
|
$conn = $dbm->acquire( $dbname ); |
|
102
|
|
|
|
|
103
|
|
|
try |
|
104
|
|
|
{ |
|
105
|
|
|
$stmt = $conn->create( 'INSERT INTO "ezuser" ( |
|
106
|
|
|
"contentobject_id", "email", "login", "login_normalized", "password_hash", "password_hash_type" |
|
107
|
|
|
) VALUES ( |
|
108
|
|
|
?, ?, ?, ?, ?, 5 |
|
109
|
|
|
)' ); |
|
110
|
|
|
|
|
111
|
|
|
$stmt->bind( 1, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
|
112
|
|
|
$stmt->bind( 2, $email ); |
|
113
|
|
|
$stmt->bind( 3, $code ); |
|
114
|
|
|
$stmt->bind( 4, $code ); |
|
115
|
|
|
$stmt->bind( 5, $password ); |
|
116
|
|
|
|
|
117
|
|
|
$stmt->execute()->finish(); |
|
118
|
|
|
|
|
119
|
|
|
$dbm->release( $conn, $dbname ); |
|
120
|
|
|
} |
|
121
|
|
|
catch( \Exception $e ) |
|
122
|
|
|
{ |
|
123
|
|
|
$dbm->release( $conn, $dbname ); |
|
124
|
|
|
throw $e; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $id; |
|
128
|
|
|
} ); |
|
129
|
|
|
|
|
130
|
|
|
return $ezContext; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.