1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Setup\Task; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Ensures service codes are unique |
14
|
|
|
*/ |
15
|
|
|
class ServiceUniqueCode extends \Aimeos\MW\Setup\Task\Base |
16
|
|
|
{ |
17
|
|
|
private $select = ' |
18
|
|
|
SELECT "code" FROM "mshop_service" GROUP BY "code" HAVING COUNT("code") > 1 |
19
|
|
|
'; |
20
|
|
|
private $update = ' |
21
|
|
|
UPDATE "mshop_service" SET "code"=? WHERE "code"=? |
22
|
|
|
AND (SELECT "id" FROM "mshop_service_type" WHERE "code"=\'delivery\') |
23
|
|
|
'; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Returns the list of task names which this task depends on. |
28
|
|
|
* |
29
|
|
|
* @return string[] List of task names |
30
|
|
|
*/ |
31
|
|
|
public function getPreDependencies() |
32
|
|
|
{ |
33
|
|
|
return []; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the list of task names which depends on this task. |
39
|
|
|
* |
40
|
|
|
* @return array List of task names |
41
|
|
|
*/ |
42
|
|
|
public function getPostDependencies() |
43
|
|
|
{ |
44
|
|
|
return ['TablesCreateMShop']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Renames all order tables if they exist. |
50
|
|
|
* |
51
|
|
|
* @param array $stmts Associative array of tables names and lists of SQL statements to execute. |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
public function migrate() |
54
|
|
|
{ |
55
|
|
|
$this->msg( 'Ensure unique codes in mshop_service', 0 ); |
56
|
|
|
$schema = $this->getSchema( 'db-service' ); |
57
|
|
|
$table = 'mshop_service'; |
58
|
|
|
|
59
|
|
|
if( $schema->tableExists( $table ) && $schema->columnExists( $table, 'code' ) ) |
60
|
|
|
{ |
61
|
|
|
$list = []; |
62
|
|
|
$conn = $this->getConnection( 'db-service' ); |
63
|
|
|
$result = $conn->create( $this->select )->execute(); |
64
|
|
|
|
65
|
|
|
while( ( $row = $result->fetch() ) !== false ) { |
66
|
|
|
$list[] = $row['code']; |
67
|
|
|
} |
68
|
|
|
$result->finish(); |
69
|
|
|
|
70
|
|
|
$stmt = $conn->create( $this->update ); |
71
|
|
|
foreach( $list as $code ) |
72
|
|
|
{ |
73
|
|
|
$stmt->bind( 1, $code ); |
74
|
|
|
$stmt->bind( 2, $code . '2' ); |
75
|
|
|
$stmt->execute()->finish(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->status( 'done' ); |
79
|
|
|
} |
80
|
|
|
else |
81
|
|
|
{ |
82
|
|
|
$this->status( 'OK' ); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.