Created
August 31, 2015 18:11
-
-
Save keithmifsud/f8ae84606d5807cd832a to your computer and use it in GitHub Desktop.
Database script to fix {"success":false,"error":{"code":"result is not an object","message":"result is not an object"}} error on vTiger Crm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file fixes an issue on vTiger. | |
* | |
* The issue relates to having a missing 'is_owner' | |
* column in 'vtiger_users' database table. | |
* | |
*/ | |
# Fill in the database connection details | |
$host = 'localhost'; | |
$port = 33060; // Possibly 3306 on your server | |
$username = 'homestead'; | |
$password = 'secret'; | |
$dbName = 'vtiger'; | |
# Place this file in a (1) web accessible directory or the root of your (2) | |
# vTiger Installation. | |
### Note ## The file needs to be on the same server as the vTiger database | |
# or else change the $host setting above. Delete this file from all servers | |
# once done. | |
# (1) If you've placed this file in a web accessible web server than simply | |
# point the browser to it and the fix is completed. | |
# (2) If you've laced this in vTiger root directory, ssh into the directory | |
# and type the the following command `php user_error_fix.php`. The terminal will let | |
# inform you if the fix was applied. | |
###### The Code Below Can Be Ignored - This is used to run the fix ##### | |
// Initiate a connection to the database | |
$connection = new mysqli($host, $username, 'some', $dbName, $port); | |
/** | |
* @return int|mysqli | |
*/ | |
$connect = function() use ($connection) { | |
if ($connection->connect_error) { | |
return print " Cannot connect to database. Please review your settings "; | |
} | |
return $connection; | |
}; | |
/** | |
* @return bool | |
*/ | |
$test = function() use ($connect) { | |
$query = "SHOW COLUMNS FROM vtiger_users LIKE = 'is_owner'"; | |
$result = mysqli_query($connect(), $query); | |
if (!$result == false) { | |
if (mysqli_num_rows($result) > 0) { | |
return false; | |
} | |
} else { | |
return true; | |
} | |
return true; | |
}; | |
/** | |
* @return bool|mysqli_result | |
*/ | |
$action = function() use ($connect) { | |
$query = "ALTER TABLE vtiger_users ADD is_owner VARCHAR (10)"; | |
return mysqli_query($connect(), $query); | |
}; | |
/** | |
* @return int | |
*/ | |
$runFix = function() use ($test, $action){ | |
if($test()){ | |
if ($action()) { | |
return print " Good job :) :) "; | |
} | |
} | |
return print " Column already exists "; | |
}; | |
/** | |
* Run the fix. | |
*/ | |
$runFix(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
could you please let me which directory should this file be copied to and how to make it work ?
I'm a newbie in this and I would appreciate the advice.
Thanks