Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to perform a SugarCRM Quick Repair and Rebuild from the line
#!/usr/bin/php
<?php
/*
* Copyright 2013
* Jeff Bickart
* @bickart
* jeff @ neposystems.com
*/
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('include/entryPoint.php');
require_once('modules/Administration/QuickRepairAndRebuild.php');
//Bug 27991 . Redirect to index.php if the request is not come from CLI.
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) != 'cgi') {
global $sugar_config;
if(!empty($sugar_config['site_url'])){
header("Location: ".$sugar_config['site_url'] . "/index.php");
}else{
sugar_die("Didn't find site url in your sugarcrm config file");
}
}
//End of #27991
if(empty($current_language)) {
$current_language = $sugar_config['default_language'];
}
$app_list_strings = return_app_list_strings_language($current_language);
$app_strings = return_application_language($current_language);
global $current_user;
$current_user = new User();
$current_user->getSystemUser();
$GLOBALS['log']->debug('--------------------------------------------> at repair.php <--------------------------------------------');
$repair = new RepairAndClear();
$repair->repairAndClearAll(array('clearAll'),array(translate('LBL_ALL_MODULES')), true,false);
$exit_on_cleanup = true;
sugar_cleanup(false);
// some jobs have annoying habit of calling sugar_cleanup(), and it can be called only once
// but job results can be written to DB after job is finished, so we have to disconnect here again
// just in case we couldn't call cleanup
if(class_exists('DBManagerFactory')) {
$db = DBManagerFactory::getInstance();
$db->disconnect();
}
if($exit_on_cleanup) exit;
@karlingen
Copy link

karlingen commented Apr 20, 2015

Does it work for 7.x as well?

@pradeepmurthy
Copy link

pradeepmurthy commented Aug 10, 2015

Thanks for this. Use this very regularly.
But could not get this execute the DB changes/scripts.
Please suggest.

@noonand
Copy link

noonand commented Jan 13, 2017

Many thanks, repaired a Sugar CRM install where a UI rebuild had gone halfway through and then failed.

@LeeForbes
Copy link

LeeForbes commented Mar 11, 2017

saved my bacon this morning! Thank you Bickart.

@stancel
Copy link

stancel commented Sep 18, 2017

This is just what I need. Thank you!

@varun2410
Copy link

varun2410 commented Mar 19, 2018

Is there any way to repair roles also from CLI?

@slushysnowman
Copy link

slushysnowman commented May 24, 2019

When I try and run this I get:
PHP Warning: htmlentities() expects parameter 1 to be string, array given in /var/www/sugar/data/SugarBean.php on line 1202 PHP Warning: htmlentities() expects parameter 1 to be string, array given in /var/www/sugar/data/SugarBean.php on line 1202 PHP Warning: htmlentities() expects parameter 1 to be string, array given in /var/www/sugar/data/SugarBean.php on line 1202 PHP Warning: htmlentities() expects parameter 1 to be string, array given in /var/www/sugar/data/SugarBean.php on line 1202 PHP Warning: Illegal string offset 'name' in /var/www/sugar/include/database/DBManager.php on line 1017 PHP Warning: Illegal string offset 'name' in /var/www/sugar/include/database/DBManager.php on line 1017 PHP Notice: Undefined index: name in /var/www/sugar/include/database/DBManager.php on line 1017 PHP Warning: Illegal string offset 'type' in /var/www/sugar/include/database/MysqlManager.php on line 367 PHP Notice: Undefined index: type in /var/www/sugar/include/database/MysqlManager.php on line 367

Any advice on how to fix?

@hmohapatra1
Copy link

hmohapatra1 commented Jun 24, 2019

How to run the code snippet once written and how to execute database changes if any?
can anyone help with these two questions please?

@bickart
Copy link
Author

bickart commented Jun 27, 2019

@hmohapatra1 there is a newer version of this program. It can be found at https://gist.github.com/esimonetti/9ca21b15dc47565b12ee73e2352da549

How to run the code snippet once written and how to execute database changes if any?
can anyone help with these two questions please?

@faruqhunter
Copy link

faruqhunter commented Jun 1, 2020

Saved my booty! -- Thanks

@andcha
Copy link

andcha commented Feb 4, 2021

Thank you so much, works fabulously on suitecrm 7.11.18

@Flying--Dutchman
Copy link

Flying--Dutchman commented Mar 13, 2021

Worked like a charm! Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment