Repository navigation
Expand file tree
/
Copy pathcli-config.php.dist
More file actions
142 lines (117 loc) · 4.72 KB
/
Copy pathcli-config.php.dist
File metadata and controls
142 lines (117 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
$db_user = 'root';
$db_pass = '';
$driver = 'pdo_sqlite';
$host = 'localhost';
$port = null;
$database = 'phpcr_benchmark';
$path = 'benchmark.sqlite';
$uri = 'http://localhost:8080/server';
$workspace = 'benchmark';
$phpcr_user = 'admin';
$phpcr_pass = 'admin';
// either 'doctrine-dbal', 'jackrabbit' or 'mongodb'
$transport = 'some-transport';
switch ($transport) {
case 'doctrine-dbal':
$factory = new \Jackalope\RepositoryFactoryDoctrineDBAL();
// Bootstrap Doctrine
$dbConn = \Doctrine\DBAL\DriverManager::getConnection(array(
'driver' => $driver,
'host' => $host,
'user' => $db_user,
'password' => $db_pass,
'dbname' => $database,
'path' => $path,
));
if (isset($argv[1]) && $argv[1] == 'jackalope:init:dbal') {
// special case: the init command needs the db connection, but a session is impossible if the db is not yet initialized
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'connection' => new \Jackalope\Tools\Console\Helper\DoctrineDbalHelper($dbConn)
));
return;
}
$parameters = array(
'jackalope.doctrine_dbal_connection' => $dbConn,
\Jackalope\Session::OPTION_AUTO_LASTMODIFIED => false,
'jackalope.logger' => new \Jackalope\Transport\Logging\Psr3Logger(new \Psr\Log\NullLogger()),
);
$optimize = in_array('--optimize', $argv);
break;
case 'jackrabbit':
$factory = new \Jackalope\RepositoryFactoryJackrabbit();
$parameters = array(
'jackalope.jackrabbit_uri' => $uri,
\Jackalope\Session::OPTION_AUTO_LASTMODIFIED => false,
'jackalope.logger' => new \Jackalope\Transport\Logging\Psr3Logger(new \Psr\Log\NullLogger()),
);
break;
case 'mongodb':
$mongoOptions = array('db' => $database);
if ($db_user) {
$mongoOptions['username'] = $db_user;
}
if ($db_pass) {
$mongoOptions['password'] = $db_pass;
}
$port = $port ?: 27017;
$mongoClient = new \MongoClient(sprintf('mongodb://%s:%s', $host, $port), $mongoOptions);
$doctrineMongoDB = new \Doctrine\MongoDB\Database(
new \Doctrine\MongoDB\Connection($mongoClient),
new \MongoDB($mongoClient, $database),
new \Doctrine\Common\EventManager()
);
$parameters = array(
'jackalope.mongodb_database' => $doctrineMongoDB
);
$factory = new \Jackalope\RepositoryFactoryMongoDB();
break;
default:
die('Pick a transport layer');
}
$credentials = new \PHPCR\SimpleCredentials($phpcr_user, $phpcr_pass);
$repository = $factory->getRepository($parameters);
$adminSession = $repository->login($credentials, 'default');
$workspaceInstance = $adminSession->getWorkspace();
if (!in_array($workspace, $workspaceInstance->getAccessibleWorkspaceNames())) {
$workspaceInstance->createWorkspace($workspace);
}
if (isset($argv[1])
&& $argv[1] != 'benchmark'
&& $argv[1] != 'list'
&& $argv[1] != 'help'
) {
$repository = $factory->getRepository($parameters);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'dialog' => new \Symfony\Component\Console\Helper\DialogHelper(),
'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($repository->login($credentials, $workspace)),
'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(),
));
return;
}
$append = in_array('--append', $argv);
$disableQuery = in_array('--disable-query', $argv);
$count = 100;
$key = array_search('--count', $argv);
if ($key && isset($argv[$key+1]) && is_numeric($argv[$key+1])) {
$count = $argv[$key+1];
}
$sections = 10;
$key = array_search('--sections', $argv);
if ($key && isset($argv[$key+1]) && is_numeric($argv[$key+1])) {
$sections = $argv[$key+1];
}
if (!$append) {
if ($factory instanceof \Jackalope\RepositoryFactoryDoctrineDBAL) {
// recreate database schema
$options = array('disable_fks' => $dbConn->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform);
$repositorySchema = new \Jackalope\Transport\DoctrineDBAL\RepositorySchema($options, $dbConn);
$repositorySchema->reset();
$workspaceInstance->createWorkspace($workspace);
} elseif ($factory instanceof \Jackalope\RepositoryFactoryMongoDB) {
// recreate database collections
$doctrineMongoDB->drop();
$workspaceInstance->createWorkspace('default');
$workspaceInstance->createWorkspace($workspace);
}
}