iF.SVNAdmin判断PHP版本的函数有缺陷,需要修改
<?php function checkPHPVersion($minimumVersion) { $phpVersion = phpversion(); $phpVersionParts = explode(".", $phpVersion); $minVersionParts = explode(".", $minimumVersion); $minVersionPartsCount = count($minVersionParts); $check = true; if ($minVersionPartsCount >= 1) if ($phpVersionParts[0] < $minVersionParts[0]) $check = false; if ($minVersionPartsCount >= 2) //if ($phpVersionParts[1] < $minVersionParts[1]) if ($phpVersionParts[0] < $minVersionParts[0] || $phpVersionParts[0] == $minVersionParts[0] && $phpVersionParts[1] < $minVersionParts[1]) $check = false; if ($minVersionPartsCount >= 3) if ($phpVersionParts[2] < $minVersionParts[2]) $check = false; return $check; }
因为我增加了维护用户的同时保存用户信息到数据库的功能,所以需要访问数据库,这个是新增文件。PHP7.0 不再支持mysql驱动,改为mysqli,所以需要修改以下操作数据库的方法:
<?php function getConnection(){ $hostname = "localhost:3306"; $username = "username"; $password = "password"; $conn = mysqli_connect($hostname,$username,$password) or die("Connection error:" . mysqli_connect_error()); $dbName = "dbname"; $ret=mysqli_select_db($conn, $dbName); return $conn; } function query($sql){ $conn = getConnection(); $res = mysqli_query($conn, $sql) or die("Connection error:" . mysqli_error($conn)); return $res; } ?>
如果是用mysql驱动,这段代码可以改为:
<?php function getConnection(){ $hostname = "localhost:3306"; $username = "username"; $password = "password"; $conn = mysql_pconnect($hostname,$username,$password) or die("Connection error:" . mysql_error()); $dbName = "dbname"; $ret=mysql_select_db($dbName,$conn); return $conn; } function query($sql){ $conn = getConnection(); $res = mysql_query($sql,$conn) or die("Connection error:" . mysql_error()); return $res; } ?>
而要保存用户信息到数据库需要修改./actions/create_user.php
// Create user object. $u = new \svnadmin\core\entities\User; $u->id = $username; $u->name = $username; $u->password = $password; try { // Create the user now. $b = $appEngine->getUserEditProvider()->addUser($u); if($b) { $appEngine->getUserEditProvider()->save(); $appEngine->addMessage(tr("The user %0 has been created successfully.", array($username))); $q = "insert IGNORE into user(name, password) values('" . $username . "', '{SHA}" . base64_encode(sha1($password, TRUE)) . "')"; query($q); }
删除用户信息:
// Delete the user. $done = $appEngine->getUserEditProvider()->deleteUser($u); if ($done) { $q = "delete from user where name = '" . $u->name . "'"; query($q); $appEngine->addMessage(tr("Removed user %0 successfully.", array($u->name))); } else { $appEngine->addException(tr("Can not remove user %0.")); }
更改密码
// Ok, change password now. $b = $appEngine->getUserEditProvider()->changePassword($username, $password); if ($b) { $appEngine->getUserEditProvider()->save(); $q = "update user set password = '{SHA}" . base64_encode(sha1($password, TRUE)) . "' where name = '" . $username . "'"; query($q); $appEngine->addMessage(tr("The password has been changed.")); }
在./include/config.inc.php这个文件的头部增加对db.inc.php的引用
error_reporting(E_ALL); include_once("./classes/util/global.func.php"); include_once("./db.inc.php"); set_exception_handler('exception_handler');