Skip to content

Commit 0b60a23

Browse files
author
Igor Zhutaiev
authored
Merge pull request #85 from sugarcrm/develop
Tidbit bin executable
2 parents de411f2 + 32bfa49 commit 0b60a23

File tree

5 files changed

+106
-30
lines changed

5 files changed

+106
-30
lines changed

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Documentation in [the wiki](https://github.com/sugarcrm/Tidbit/wiki)!
1717
Requirements
1818
------------
1919
PHP 5.3+
20-
Sugar Already installed (6.5+ versions)
20+
Sugar Already installed (6.7+ versions)
2121

2222
Installation
2323
------------
@@ -101,41 +101,47 @@ values (integer starting with 1) for autoincrement-type fields.
101101
102102
Tidbit uses a command line interface. To run it from the Tidbit directory:
103103
104-
$ php -f install_cli.php
104+
$ ./bin/tidbit (or ./vendor/bin/tidbit for package dependency installation)
105105
106106
Various options are available to control the number of entries generated.
107107
To view them:
108108
109-
$ php -f install_cli.php -- -h
109+
$ ./bin/tidbit -h
110110
111111
Example usages:
112112
113113
* Clean out existing seed data when generating new data set:
114-
$ php -f install_cli.php -- -c
114+
$ ./bin/tidbit -c
115115
116116
* Insert 500 users:
117-
$ php -f install_cli.php -- -u 500
117+
$ ./bin/tidbit -u 500
118118
119119
* Generate data into csv (mysql is default):
120-
$ php -f install_cli.php -- --storage csv
120+
$ ./bin/tidbit --storage csv
121121
122122
* Generate records for all out-of-box and custom modules, plus find all relationships
123-
$ php -f install_cli.php -- --allmodules --allrelationships
123+
$ ./bin/tidbit --allmodules --allrelationships
124124
125125
* Obliterate all data when generating new records with 400 users:
126-
$php -f install_cli.php -- -o -u 400
127-
126+
$ ./bin/tidbit -o -u 400
127+
128+
* Use profile (pre-existing one: simple, simple_rev2, average, high) file to generate data
129+
$ ./bin/tidbit -o --profile simple --sugar_path /some/sugar/path
130+
131+
* Use custom profile (located in /path/to/profile/file)
132+
$ ./bin/tidbit -o --profile /path/to/profile --sugar_path /some/sugar/path
133+
128134
* Generate TeamBasedACL action restrictions for chosen level (check level options in config files)
129-
$php -f install_cli.php -- -o --tba -tba_level full
135+
$ ./bin/tidbit -o --tba -tba_level full
130136
131137
* Controlling INSERT_BATCH_SIZE (MySQL Support only for now)
132-
$php -f install_cli.php -- -o --insert_batch_size 1000
138+
$ ./bin/tidbit -o --insert_batch_size 1000
133139
134140
* Setting path to SugarCRM installation
135-
$php -f install_cli.php -- -o --sugar_path /some/sugar/path
141+
$ ./bin/tidbit -o --sugar_path /some/sugar/path
136142
137143
* Using DB2 storage example (mysql/oracle/db2 can be used, depending on Sugar installation and DB usage)
138-
$php -f install_cli.php -- -o --sugar_path /some/sugar/path --storage db2
144+
$ ./bin/tidbit -o --sugar_path /some/sugar/path --storage db2
139145
140146
Contributing:
141147
------------

bin/tidbit

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*********************************************************************************
5+
* Tidbit is a data generation tool for the SugarCRM application developed by
6+
* SugarCRM, Inc. Copyright (C) 2004-2016 SugarCRM Inc.
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU Affero General Public License version 3 as published by the
10+
* Free Software Foundation with the addition of the following permission added
11+
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12+
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13+
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14+
*
15+
* This program is distributed in the hope that it will be useful, but WITHOUT
16+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17+
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18+
* details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License along with
21+
* this program; if not, see http://www.gnu.org/licenses or write to the Free
22+
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23+
* 02110-1301 USA.
24+
*
25+
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26+
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27+
*
28+
* The interactive user interfaces in modified source and object code versions
29+
* of this program must display Appropriate Legal Notices, as required under
30+
* Section 5 of the GNU Affero General Public License version 3.
31+
*
32+
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33+
* these Appropriate Legal Notices must retain the display of the "Powered by
34+
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
35+
* technical reasons, the Appropriate Legal Notices must display the words
36+
* "Powered by SugarCRM".
37+
********************************************************************************/
38+
39+
/**
40+
* if Tidbit is running independently, the dependencies are in the /vendor
41+
* directory, but if Tidbit is part of a larger composer managed system, the
42+
* dependencies are a couple directories higher. If neither are found, bail
43+
*
44+
* @return boolean
45+
*/
46+
function checkAutoloader() {
47+
$files = array(
48+
__DIR__ . '/../../../autoload.php', // composer dependency
49+
__DIR__ . '/../vendor/autoload.php', // stand-alone package
50+
);
51+
foreach ($files as $file) {
52+
if (is_file($file)) {
53+
require_once $file;
54+
return true;
55+
}
56+
}
57+
return false;
58+
};
59+
60+
if (!checkAutoloader()) {
61+
die(
62+
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
63+
'curl -sS https://getcomposer.org/installer | php' . PHP_EOL .
64+
'php composer.phar install' . PHP_EOL
65+
);
66+
}
67+
68+
define('TIDBIT_CLI_START', true);
69+
70+
// Start Tidbit
71+
require_once __DIR__ . '/../install_cli.php';

bootstrap.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@
156156

157157
require_once __DIR__ . '/install_functions.php';
158158

159+
if (!defined('TIDBIT_CLI_START')) {
160+
exitWithError('Tidbit should be run with "./bin/tidbit" or "./vendor/bin/tidbit" instead');
161+
}
162+
159163
if (!function_exists('getopt')) {
160-
exitWithError('"getopt" function not found. Please make sure you are running PHP 5+ version');
164+
exitWithError('"getopt" function not found. Please make sure you are running PHP 5.3+ version');
161165
}
162166

163167
$opts = getopt(
@@ -202,19 +206,6 @@
202206
define('DATA_DIR', CONFIG_DIR . '/data');
203207
define('RELATIONSHIPS_DIR', CONFIG_DIR . '/relationships');
204208

205-
/*
206-
* if Tidbit is running independently, the dependencies are in the /vendor
207-
* directory, but if Tidbit is part of a larger composer managed system, the
208-
* dependencies are a couple directories higher. If neither are found, bail
209-
*/
210-
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
211-
require_once __DIR__ . '/vendor/autoload.php';
212-
} elseif (file_exists(__DIR__ . '../../autoload.php')) {
213-
require_once __DIR__ . '../../autoload.php';
214-
} else {
215-
exitWithError('Unable to locate composer\'s autoload.php file');
216-
}
217-
218209
// load general config
219210
require_once CONFIG_DIR . '/config.php';
220211

@@ -238,7 +229,14 @@
238229
$sugarPath = $opts['sugar_path'];
239230
}
240231
if (!is_file($sugarPath . '/include/entryPoint.php')) {
241-
exitWithError("Where is no Sugar on path " . $sugarPath . " ... exiting");
232+
// Check current user directory
233+
$currentDirectory = getcwd();
234+
235+
if (is_file($currentDirectory . '/include/entryPoint.php')) {
236+
$sugarPath = $currentDirectory;
237+
} else {
238+
exitWithError("Where is no Sugar on path " . $sugarPath . " ... exiting");
239+
}
242240
}
243241

244242
define('SUGAR_PATH', $sugarPath);

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"issues" : "https://github.com/sugarcrm/tidbit/issues"
1818
},
1919
"require" : {
20+
"php": ">=5.3.27"
2021
},
2122
"require-dev": {
2223
"phpunit/phpunit": "4.*",
@@ -32,5 +33,6 @@
3233
"check-style" : "./vendor/bin/phpcs --standard=./ruleset.xml",
3334
"tests" : "./vendor/bin/phpunit",
3435
"tests-ci" : "./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml"
35-
}
36+
},
37+
"bin": ["bin/tidbit"]
3638
}

install_cli.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/local/bin/php
21
<?php
32

43
/*********************************************************************************

0 commit comments

Comments
 (0)