Skip to content

Commit

Permalink
Merge pull request #79 from izhutaev-sugarcrm/bin_link
Browse files Browse the repository at this point in the history
Tidbit CLI script to run via composer
  • Loading branch information
Igor Zhutaiev committed Sep 20, 2016
2 parents 54ef494 + 320a77e commit 32bfa49
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 30 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Documentation in [the wiki](https://github.com/sugarcrm/Tidbit/wiki)!
Requirements
------------
PHP 5.3+
Sugar Already installed (6.5+ versions)
Sugar Already installed (6.7+ versions)

Installation
------------
Expand Down Expand Up @@ -101,41 +101,47 @@ values (integer starting with 1) for autoincrement-type fields.

Tidbit uses a command line interface. To run it from the Tidbit directory:

$ php -f install_cli.php
$ ./bin/tidbit (or ./vendor/bin/tidbit for package dependency installation)

Various options are available to control the number of entries generated.
To view them:

$ php -f install_cli.php -- -h
$ ./bin/tidbit -h

Example usages:

* Clean out existing seed data when generating new data set:
$ php -f install_cli.php -- -c
$ ./bin/tidbit -c

* Insert 500 users:
$ php -f install_cli.php -- -u 500
$ ./bin/tidbit -u 500
* Generate data into csv (mysql is default):
$ php -f install_cli.php -- --storage csv
$ ./bin/tidbit --storage csv

* Generate records for all out-of-box and custom modules, plus find all relationships
$ php -f install_cli.php -- --allmodules --allrelationships
$ ./bin/tidbit --allmodules --allrelationships

* Obliterate all data when generating new records with 400 users:
$php -f install_cli.php -- -o -u 400
$ ./bin/tidbit -o -u 400

* Use profile (pre-existing one: simple, simple_rev2, average, high) file to generate data
$ ./bin/tidbit -o --profile simple --sugar_path /some/sugar/path

* Use custom profile (located in /path/to/profile/file)
$ ./bin/tidbit -o --profile /path/to/profile --sugar_path /some/sugar/path

* Generate TeamBasedACL action restrictions for chosen level (check level options in config files)
$php -f install_cli.php -- -o --tba -tba_level full
$ ./bin/tidbit -o --tba -tba_level full
* Controlling INSERT_BATCH_SIZE (MySQL Support only for now)
$php -f install_cli.php -- -o --insert_batch_size 1000
$ ./bin/tidbit -o --insert_batch_size 1000

* Setting path to SugarCRM installation
$php -f install_cli.php -- -o --sugar_path /some/sugar/path
$ ./bin/tidbit -o --sugar_path /some/sugar/path

* Using DB2 storage example (mysql/oracle/db2 can be used, depending on Sugar installation and DB usage)
$php -f install_cli.php -- -o --sugar_path /some/sugar/path --storage db2
$ ./bin/tidbit -o --sugar_path /some/sugar/path --storage db2

Contributing:
------------
Expand Down
71 changes: 71 additions & 0 deletions bin/tidbit
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env php
<?php

/*********************************************************************************
* Tidbit is a data generation tool for the SugarCRM application developed by
* SugarCRM, Inc. Copyright (C) 2004-2016 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/

/**
* if Tidbit is running independently, the dependencies are in the /vendor
* directory, but if Tidbit is part of a larger composer managed system, the
* dependencies are a couple directories higher. If neither are found, bail
*
* @return boolean
*/
function checkAutoloader() {
$files = array(
__DIR__ . '/../../../autoload.php', // composer dependency
__DIR__ . '/../vendor/autoload.php', // stand-alone package
);
foreach ($files as $file) {
if (is_file($file)) {
require_once $file;
return true;
}
}
return false;
};

if (!checkAutoloader()) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -sS https://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}

define('TIDBIT_CLI_START', true);

// Start Tidbit
require_once __DIR__ . '/../install_cli.php';
28 changes: 13 additions & 15 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@

require_once __DIR__ . '/install_functions.php';

if (!defined('TIDBIT_CLI_START')) {
exitWithError('Tidbit should be run with "./bin/tidbit" or "./vendor/bin/tidbit" instead');
}

if (!function_exists('getopt')) {
exitWithError('"getopt" function not found. Please make sure you are running PHP 5+ version');
exitWithError('"getopt" function not found. Please make sure you are running PHP 5.3+ version');
}

$opts = getopt(
Expand Down Expand Up @@ -202,19 +206,6 @@
define('DATA_DIR', CONFIG_DIR . '/data');
define('RELATIONSHIPS_DIR', CONFIG_DIR . '/relationships');

/*
* if Tidbit is running independently, the dependencies are in the /vendor
* directory, but if Tidbit is part of a larger composer managed system, the
* dependencies are a couple directories higher. If neither are found, bail
*/
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
} elseif (file_exists(__DIR__ . '../../autoload.php')) {
require_once __DIR__ . '../../autoload.php';
} else {
exitWithError('Unable to locate composer\'s autoload.php file');
}

// load general config
require_once CONFIG_DIR . '/config.php';

Expand All @@ -238,7 +229,14 @@
$sugarPath = $opts['sugar_path'];
}
if (!is_file($sugarPath . '/include/entryPoint.php')) {
exitWithError("Where is no Sugar on path " . $sugarPath . " ... exiting");
// Check current user directory
$currentDirectory = getcwd();

if (is_file($currentDirectory . '/include/entryPoint.php')) {
$sugarPath = $currentDirectory;
} else {
exitWithError("Where is no Sugar on path " . $sugarPath . " ... exiting");
}
}

define('SUGAR_PATH', $sugarPath);
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"issues" : "https://github.com/sugarcrm/tidbit/issues"
},
"require" : {
"php": ">=5.3.27"
},
"require-dev": {
"phpunit/phpunit": "4.*",
Expand All @@ -32,5 +33,6 @@
"check-style" : "./vendor/bin/phpcs --standard=./ruleset.xml",
"tests" : "./vendor/bin/phpunit",
"tests-ci" : "./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml"
}
},
"bin": ["bin/tidbit"]
}
1 change: 0 additions & 1 deletion install_cli.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/local/bin/php
<?php

/*********************************************************************************
Expand Down

0 comments on commit 32bfa49

Please sign in to comment.