|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Example\Migrations\TestAntiMattr\MongoDB; |
|
4
|
|
|
|
|
5
|
|
|
use AntiMattr\MongoDB\Migrations\AbstractMigration; |
|
6
|
|
|
use MongoDB\Database; |
|
7
|
|
|
|
|
8
|
|
|
class Version20140822185742 extends AbstractMigration |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @return string |
|
12
|
|
|
*/ |
|
13
|
|
|
public function getDescription() |
|
14
|
|
|
{ |
|
15
|
|
|
return 'First Version prepares Index'; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function up(Database $db) |
|
19
|
|
|
{ |
|
20
|
|
|
$testA = $db->selectCollection('test_a'); |
|
21
|
|
|
$this->analyze($testA); |
|
22
|
|
|
|
|
23
|
|
|
$testA->createIndex(['actor' => -1]); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function down(Database $db) |
|
27
|
|
|
{ |
|
28
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* This preUp is not required |
|
33
|
|
|
* I use it to demonstrate the analyzer. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function preUp(Database $db) |
|
36
|
|
|
{ |
|
37
|
|
|
$testA = $db->selectCollection('test_a'); |
|
38
|
|
|
|
|
39
|
|
|
$testDocuments = []; |
|
40
|
|
|
|
|
41
|
|
|
for ($i = 0; $i < 100; ++$i) { |
|
42
|
|
|
$testDocument = []; |
|
43
|
|
|
$testDocument['iteration'] = $i; |
|
44
|
|
|
$testDocument['actor'] = $this->generateRandomString(); |
|
|
|
|
|
|
45
|
|
|
$testDocument['object'] = $this->generateRandomString(); |
|
46
|
|
|
$testDocument['target'] = $this->generateRandomString(); |
|
47
|
|
|
$testDocument['verb'] = $this->generateRandomString(); |
|
48
|
|
|
$testDocuments[] = $testDocument; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$testA->insertMany($testDocuments); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* This postUp is not required |
|
56
|
|
|
* I use it to demonstrate the analyzer. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function postUp(Database $db) |
|
59
|
|
|
{ |
|
60
|
|
|
$testA = $db->selectCollection('test_a'); |
|
61
|
|
|
$testA->drop(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private function generateRandomString() |
|
65
|
|
|
{ |
|
66
|
|
|
$length = rand(10, 50); |
|
67
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
68
|
|
|
$randomString = ''; |
|
69
|
|
|
for ($i = 0; $i < $length; ++$i) { |
|
70
|
|
|
$randomString .= $characters[rand(0, strlen($characters) - 1)]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $randomString; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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.