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 the required address fields to ezuser table |
14
|
|
|
*/ |
15
|
|
|
class EzuserAddAddress extends \Aimeos\MW\Setup\Task\TablesCreateMShop |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Returns the list of task names which depends on this task. |
19
|
|
|
* |
20
|
|
|
* @return array List of task names |
21
|
|
|
*/ |
22
|
|
|
public function getPostDependencies() |
23
|
|
|
{ |
24
|
|
|
return array(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Migrate database schema |
30
|
|
|
*/ |
31
|
|
|
public function migrate() |
32
|
|
|
{ |
33
|
|
|
$this->msg( 'Adding address fields to ezuser table', 0 ); |
34
|
|
|
|
35
|
|
|
$dbal = $this->getConnection( 'db-customer' )->getRawObject(); |
36
|
|
|
|
37
|
|
|
if( !( $dbal instanceof \Doctrine\DBAL\Connection ) ) { |
|
|
|
|
38
|
|
|
throw new \Aimeos\MW\Setup\Exception( 'Not a DBAL connection' ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
$fromSchema = $dbal->getSchemaManager()->createSchema(); |
43
|
|
|
$comparator = new \Doctrine\DBAL\Schema\Comparator(); |
|
|
|
|
44
|
|
|
$toSchema = clone $fromSchema; |
45
|
|
|
|
46
|
|
|
$this->addIndexes( $this->addColumns( $toSchema->getTable( 'ezuser' ) ) ); |
47
|
|
|
$sql = $fromSchema->getMigrateToSql( $toSchema, $dbal->getDatabasePlatform() ); |
48
|
|
|
|
49
|
|
|
if( $sql !== array() ) |
50
|
|
|
{ |
51
|
|
|
$this->executeList( $sql, 'db-customer' ); |
52
|
|
|
$this->status( 'done' ); |
53
|
|
|
} |
54
|
|
|
else |
55
|
|
|
{ |
56
|
|
|
$this->status( 'OK' ); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Adds the missing columns to the table |
63
|
|
|
* |
64
|
|
|
* @param \Doctrine\DBAL\Schema\Table $table Table object |
65
|
|
|
* @return \Doctrine\DBAL\Schema\Table Updated table object |
66
|
|
|
*/ |
67
|
|
|
protected function addColumns( \Doctrine\DBAL\Schema\Table $table ) |
68
|
|
|
{ |
69
|
|
|
$columns = array( |
70
|
|
|
'company' => array( 'string', array( 'length' => 100 ) ), |
71
|
|
|
'vatid' => array( 'string', array( 'length' => 32 ) ), |
72
|
|
|
'salutation' => array( 'string', array( 'length' => 8 ) ), |
73
|
|
|
'title' => array( 'string', array( 'length' => 64 ) ), |
74
|
|
|
'firstname' => array( 'string', array( 'length' => 64 ) ), |
75
|
|
|
'address1' => array( 'string', array( 'length' => 255 ) ), |
76
|
|
|
'address2' => array( 'string', array( 'length' => 255 ) ), |
77
|
|
|
'address3' => array( 'string', array( 'length' => 255 ) ), |
78
|
|
|
'postal' => array( 'string', array( 'length' => 16 ) ), |
79
|
|
|
'city' => array( 'string', array( 'length' => 255 ) ), |
80
|
|
|
'state' => array( 'string', array( 'length' => 255 ) ), |
81
|
|
|
'langid' => array( 'string', array( 'length' => 5, 'notnull' => false ) ), |
82
|
|
|
'countryid' => array( 'string', array( 'length' => 2, 'notnull' => false, 'fixed' => true ) ), |
83
|
|
|
'telephone' => array( 'string', array( 'length' => 32 ) ), |
84
|
|
|
'telefax' => array( 'string', array( 'length' => 32 ) ), |
85
|
|
|
'website' => array( 'string', array( 'length' => 255 ) ), |
86
|
|
|
'birthday' => array( 'date', array( 'notnull' => false ) ), |
87
|
|
|
'vdate' => array( 'date', array( 'notnull' => false ) ), |
88
|
|
|
'status' => array( 'smallint', array() ), |
89
|
|
|
'mtime' => array( 'datetime', array() ), |
90
|
|
|
'ctime' => array( 'datetime', array() ), |
91
|
|
|
'editor' => array( 'string', array( 'length' => 255 ) ), |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
foreach( $columns as $name => $def ) |
95
|
|
|
{ |
96
|
|
|
if( $table->hasColumn( $name ) === false ) { |
97
|
|
|
$table->addColumn( $name, $def[0], $def[1] ); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $table; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Adds the missing indexes to the table |
107
|
|
|
* |
108
|
|
|
* @param \Doctrine\DBAL\Schema\Table $table Table object |
109
|
|
|
* @return \Doctrine\DBAL\Schema\Table Updated table object |
110
|
|
|
*/ |
111
|
|
|
protected function addIndexes( \Doctrine\DBAL\Schema\Table $table ) |
112
|
|
|
{ |
113
|
|
|
$indexes = array( |
114
|
|
|
'idx_ezpus_langid' => array( 'langid' ), |
115
|
|
|
'idx_ezpus_status_ln_fn' => array( 'status', 'lastname', 'firstname' ), |
116
|
|
|
'idx_ezpus_status_ad1_ad2' => array( 'status', 'address1', 'address2' ), |
117
|
|
|
'idx_ezpus_status_postal_city' => array( 'status', 'postal', 'city' ), |
118
|
|
|
'idx_ezpus_lastname' => array( 'lastname' ), |
119
|
|
|
'idx_ezpus_address1' => array( 'address1' ), |
120
|
|
|
'idx_ezpus_postal' => array( 'postal' ), |
121
|
|
|
'idx_ezpus_city' => array( 'city' ), |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
foreach( $indexes as $name => $def ) |
125
|
|
|
{ |
126
|
|
|
if( $table->hasIndex( $name ) === false ) { |
127
|
|
|
$table->addIndex( $def, $name ); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return $table; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.