/**
* @brief Function to check if the Database structure needs an update.
*
+ * @param string $basePath The base path of this application
* @param boolean $via_worker boolean Is the check run via the worker?
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function check($via_worker)
+ public static function check($basePath, $via_worker)
{
+ if (!DBA::connected()) {
+ return;
+ }
+
$build = Config::get('system', 'build');
if (empty($build)) {
}
if ($build < DB_UPDATE_VERSION) {
- // When we cannot execute the database update via the worker, we will do it directly
- if (!Worker::add(PRIORITY_CRITICAL, 'DBUpdate') && $via_worker) {
- self::run();
+ if ($via_worker) {
+ // Calling the database update directly via the worker enables us to perform database changes to the workerqueue table itself.
+ // This is a fallback, since normally the database update will be performed by a worker job.
+ // This worker job doesn't work for changes to the "workerqueue" table itself.
+ self::run($basePath);
+ } else {
+ Worker::add(PRIORITY_CRITICAL, 'DBUpdate');
}
}
}
/**
* Automatic database updates
*
- * @param bool $force Force the Update-Check even if the lock is set
- * @param bool $verbose Run the Update-Check verbose
- * @param bool $sendMail Sends a Mail to the administrator in case of success/failure
+ * @param string $basePath The base path of this application
+ * @param bool $force Force the Update-Check even if the database version doesn't match
+ * @param bool $override Overrides any running/stuck updates
+ * @param bool $verbose Run the Update-Check verbose
+ * @param bool $sendMail Sends a Mail to the administrator in case of success/failure
*
* @return string Empty string if the update is successful, error messages otherwise
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function run($force = false, $verbose = false, $sendMail = true)
+ public static function run($basePath, $force = false, $override = false, $verbose = false, $sendMail = true)
{
// In force mode, we release the dbupdate lock first
// Necessary in case of an stuck update
- if ($force) {
- Lock::release('dbupdate');
+ if ($override) {
+ Lock::release('dbupdate', true);
}
$build = Config::get('system', 'build');
Config::set('system', 'build', $build);
}
- if ($build != DB_UPDATE_VERSION) {
+ if ($build != DB_UPDATE_VERSION || $force) {
require_once 'update.php';
$stored = intval($build);
$current = intval(DB_UPDATE_VERSION);
- if ($stored < $current) {
+ if ($stored < $current || $force) {
Config::load('database');
Logger::log('Update from \'' . $stored . '\' to \'' . $current . '\' - starting', Logger::DEBUG);
}
// update the structure in one call
- $retval = DBStructure::update($verbose, true);
- if ($retval) {
+ $retval = DBStructure::update($basePath, $verbose, true);
+ if (!empty($retval)) {
if ($sendMail) {
self::updateFailed(
DB_UPDATE_VERSION,
/**
* Executes a specific update function
*
- * @param int $x the DB version number of the function
+ * @param int $x the DB version number of the function
* @param string $prefix the prefix of the function (update, pre_update)
*
* @return bool true, if the update function worked
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function runUpdateFunction($x, $prefix)
{
/**
* send the email and do what is needed to do on update fails
*
- * @param int $update_id number of failed update
- * @param string $error_message error message
+ * @param int $update_id number of failed update
+ * @param string $error_message error message
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function updateFailed($update_id, $error_message) {
//send the administrators an e-mail
- $admin_mail_list = "'".implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
- $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['`email` IN (%s)', $admin_mail_list]);
+ $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['email' => explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))]);
// No valid result?
if (!DBA::isResult($adminlist)) {
private static function updateSuccessfull($from_build, $to_build)
{
//send the administrators an e-mail
- $admin_mail_list = "'".implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'";
- $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['`email` IN (%s)', $admin_mail_list]);
+ $adminlist = DBA::select('user', ['uid', 'language', 'email'], ['email' => explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))]);
if (DBA::isResult($adminlist)) {
// every admin could had different language