From: <rgr...@us...> - 2013-08-28 02:02:26
|
Revision: 11988 http://sourceforge.net/p/xoops/svn/11988 Author: rgriffith Date: 2013-08-28 02:02:20 +0000 (Wed, 28 Aug 2013) Log Message: ----------- Drop of Doctrine Branch Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/functions.ini.php XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/object.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/xoopscaptcha.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/manager.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabase.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/sqlutility.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/model/write.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/module.textsanitizer.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/utility/xoopsutility.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xml/rpc/xoopsapi.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoopslists.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoopsload.php XoopsCore/branches/2.6.x/2.6.0/htdocs/include/common.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/block.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/blockmodulelink.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/cachemodel.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/configcategory.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/configitem.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/configoption.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/group.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/groupperm.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/member.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/membership.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/module.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/object.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/online.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/privmessage.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/ranks.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/session.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/tplfile.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/tplset.php XoopsCore/branches/2.6.x/2.6.0/htdocs/kernel/user.php XoopsCore/branches/2.6.x/2.6.0/htdocs/lostpass.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/avatars/admin/avatar_custom.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/avatars/admin/avatar_system.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/avatars/class/avatar.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/avatars/class/userlink.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/avatars/editavatar.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/avatars/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/banners/class/banner.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/banners/class/bannerclient.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/banners/class/bannerrender.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/banners/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comment.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/images/class/category.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/images/class/image.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/images/class/imagebody.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/logger/plugins/firephp/logger.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/logger/plugins/legacy/render.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/logger/plugins/pqp/logger.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/logger/preloads/core.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/maintenance/admin/center.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/maintenance/admin/dump.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/maintenance/class/maintenance.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/menus/class/menu.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/menus/class/menus.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/notifications/class/notification.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/notifications/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_content.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_rating.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_related.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_related_link.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/plugin/notifications.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/plugin/search.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/pm/class/message.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/pm/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/pm/include/update.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/class/category.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/class/field.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/class/profile.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/class/regstep.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/class/visibility.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/include/update.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/lostpass.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/search.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/admin/advisory.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/admin/center.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/admin/index.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/admin/prefix_manager.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/class/form/center.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/class/protector.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/include/postcheck.inc.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/protector/include/postcheck_functions.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/admin/permissions.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/archive.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/category.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/file.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/item.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/mimetype.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/permission.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/notifications.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/rating.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/search.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/smilies/class/smiley.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/admin/users/jquery.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/admin/users/users.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/blocks/info.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/class/module.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/system/include/update.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/userconfigs/class/item.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/userconfigs/class/option.php XoopsCore/branches/2.6.x/2.6.0/htdocs/pda.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Auth/Ads.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Auth/Factory.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Auth/Ldap.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Auth/Xoops.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Auth.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Object/Dtype/Abstract.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops/Registry.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/Xoops.php Added Paths: ----------- XoopsCore/branches/2.6.x/2.6.0/UnitTestXoops/ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/connection.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabaseproxy.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/mysqldatabasesafe.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/querybuilder.php XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/composer.json XoopsCore/branches/2.6.x/2.6.0/htdocs/xoops_lib/vendor/ Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/functions.ini.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/functions.ini.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/functions.ini.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -152,7 +152,7 @@ if ($isRel) { return $relative_name; } - return $xoops->db()->prefix($relative_name); + return $xoopsDB->prefix($relative_name); } } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/object.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/object.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/Frameworks/art/object.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -62,7 +62,7 @@ /** * Constructor * - * @param object $db reference to the {@link XoopsDatabase} object + * @param object $db reference to the {@link XoopsConnection} object **/ function __construct($db, $table, $className, $keyName, $identifierName) Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/recaptcha.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -45,11 +45,12 @@ require_once dirname(__FILE__) . '/recaptcha/recaptchalib.php'; $form = "<script type=\"text/javascript\"> var RecaptchaOptions = { - theme : '" . $this->config['theme'] . "', - lang : '" . $this->config['lang'] . "' + theme : '" . (empty($this->config['theme']) ? '' : $this->config['theme']) . "', + lang : '" . (empty($this->config['lang']) ? '' : $this->config['lang']) . "' }; </script>"; - $form .= recaptcha_get_html($this->config['public_key']); + $public_key = empty($this->config['public_key']) ? '' : $this->config['public_key']; + $form .= recaptcha_get_html($public_key); return $form; } @@ -59,7 +60,7 @@ * @param $sessionName * @return bool */ - public function verify($sessionName) + public function verify($sessionName = null) { $is_valid = false; require_once dirname(__FILE__) . '/recaptcha/recaptchalib.php'; Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/xoopscaptcha.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/xoopscaptcha.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/captcha/xoopscaptcha.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -475,9 +475,12 @@ */ public function loadConfig($name = '') { - $this->config = empty($name) ? $this->handler->config - : array_merge($this->handler->config, $this->handler->loadConfig($name)); - + if (!is_object($this->handler)) + $this->config = array(); + else + $this->config = empty($name) + ? $this->handler->config + : array_merge($this->handler->config, $this->handler->loadConfig($name)); } /** Copied: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/connection.php (from rev 11987, XoopsCore/branches/2.6.x/2.6.0_doctrine/htdocs/class/database/connection.php) =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/connection.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/connection.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -0,0 +1,233 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. + */ + +/** + * Connection wrapper for Doctrine DBAL Connection + * + * PHP version 5.3 + * + * @category Xoops\Database\Connection + * @package Connection + * @author readheadedrod <red...@ho...> + * @author Richard Griffith <ri...@ge...> + * @copyright 2013 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) + * @version Release: 2.6 + * @link http://xoops.org + * @since 2.6.0 + */ +class XoopsConnection extends \Doctrine\DBAL\Connection +{ + /** + * @var bool $safe true means it is safe to update pages or write to database + * removed allowedWebChanges as unnecessary. Using this instead. + */ + private $safe = true; + + + /** + * @var bool $force true means force SQL even if safe is not true. + */ + private $force = false; + + + /** + * Initializes a new instance of the Connection class. + * + * This sets up necessary variables before calling parent constructor + * + * @param array $params Parameters for the driver + * @param Driver $driver The driver to use + * @param Configuration $config The connection configuration + * @param EventManager $eventManager Event manager to use + */ + public function __construct( + array $params, + \Doctrine\DBAL\Driver\PDOMySql\Driver $driver, + \Doctrine\DBAL\Configuration $config = null, + \Doctrine\Common\EventManager $eventManager = null + ) { + if (!defined('XOOPS_DB_PROXY') || ($_SERVER['REQUEST_METHOD'] != 'GET')) { + $this->safe = true; + } else { + $this->safe = false; + } + parent::__construct($params, $driver, $config, $eventManager); + } + + /** + * Prepend the prefix.'_' to the given tablename + * If tablename is empty, just return the prefix. + * + * @param string $tablename tablename + * + * @return string prefixed tablename, or prefix if tablename is empty + */ + public static function prefix($tablename = '') + { + static $prefix = XOOPS_DB_PREFIX; + if ($tablename != '') { + return $prefix . '_' . $tablename; + } else { + return $prefix; + } + } + + /** + * Inserts a table row with specified data. + * + * Adds prefix to the name of the table then passes to normal function. + * + * @param string $tableName The name of the table to insert data into. + * @param array $data An associative array containing column-value pairs. + * @param array $types Types of the inserted data. + * + * @return integer The number of affected rows. + */ + public function insertPrefix($tableName, array $data, array $types = array()) + { + $tableName = $this->prefix($tableName); + return $this->insert($tableName, $data, $types); + } + + + /** + * Executes an SQL UPDATE statement on a table. + * + * Adds prefix to the name of the table then passes to normal function. + * + * @param string $tableName The name of the table to update. + * @param array $data The data to update + * @param array $identifier The update criteria. + * An associative array containing column-value pairs. + * @param array $types Types of the merged $data and + * $identifier arrays in that order. + * + * @return integer The number of affected rows. + */ + public function updatePrefix($tableName, array $data, array $identifier, array $types = array()) + { + $tableName = $this->prefix($tableName); + return $this->update($tableName, $data, $identifier, $types); + } + + + /** + * Executes an SQL DELETE statement on a table. + * + * Adds prefix to the name of the table then passes to normal function. + * + * @param string $tableName The name of the table on which to delete. + * @param array $identifier The deletion criteria. + * An associative array containing column-value pairs. + * + * @return integer The number of affected rows. + */ + public function deletePrefix($tableName, array $identifier) + { + $tableName = $this->prefix($tableName); + return $this->delete($tableName, $identifier); + } + + + + /** + * perform a query on the database + * Always performs query and triggers timer to time it + * + * @return bool|resource query result or FALSE if not successful + * or TRUE if successful and no result + */ + public function queryForce() + { + $sql = func_get_arg(0); + $xoopsPreload = XoopsPreload::getInstance(); + $xoopsPreload->triggerEvent('core.database.query.start'); + try { + $result = call_user_func_array(array('parent', 'query'), func_get_args()); + } catch (Exception $e) { + $result=false; + } + /* if(is_object($result)) { + $this->_lastResult = clone $result; + } */ // Remove if not using getAffectedRows + $xoopsPreload->triggerEvent('core.database.query.end'); + + if ($result) { + $xoopsPreload->triggerEvent('core.database.query.success', (array($sql))); + return $result; + } else { + $xoopsPreload->triggerEvent('core.database.query.failure', (array($sql, $this))); + return false; + } + } + + /** + * perform a safe query if allowed + * can receive variable number of arguments + * + * @return returns the value received from queryForce + */ + public function query() + { + if ($this->safe) { + return call_user_func_array(array($this, "queryForce"), func_get_args()); + } else { + $sql = ltrim(func_get_arg(0)); + if (!$this->safe && strtolower(substr($sql, 0, 6))!= 'select') { + //trigger_error('Database updates are not allowed + //during processing of a GET request', E_USER_WARNING); + //needs to be replaced with standard error + return false; + } + return call_user_func_array(array($this, "queryForce"), func_get_args()); + } + } + + /** + * perform queries from SQL dump file in a batch + * + * @param string $file file path to an SQL dump file + * + * @return bool FALSE if failed reading SQL file or + * TRUE if the file has been read and queries executed + */ + public function queryFromFile($file) + { + if (false !== ($fp = fopen($file, 'r'))) { + $sql_queries = trim(fread($fp, filesize($file))); + SqlUtility::splitMySqlFile($pieces, $sql_queries); + foreach ($pieces as $query) { + // [0] contains the prefixed query + // [4] contains unprefixed table name + $prefixed_query = SqlUtility::prefixQuery( + trim($query), + $this->prefix() + ); + if ($prefixed_query != false) { + $this->query($prefixed_query[0]); + } + } + return true; + } + return false; + } + + /** + * Create a new instance of a SQL query builder. + * + * @return \Doctrine\DBAL\Query\QueryBuilder + */ + public function createXoopsQueryBuilder() + { + return new XoopsQueryBuilder($this); + } +} Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/database.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -1,35 +1,29 @@ <?php -/* - You may not change or alter any portion of this comment or credits - of supporting developers from this source code or any supporting source code - which is considered copyrighted (c) material of the original comment or credit authors. +/** + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. - 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. -*/ - -/** - * Abstract base class for XOOPS Database access classes - * - * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ - * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package class - * @subpackage database - * @since 1.0.0 - * @author Kazumi Ono <on...@xo...> - * @version $Id$ + 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. */ -defined('XOOPS_ROOT_PATH') or die('Restricted access'); - /** * Abstract base class for Database access classes * + * PHP version 5.3 + * + * @category Xoops\Class\Database\Database + * @package Database + * @author Kazumi Ono <on...@xo...> + * @copyright 2013 The XOOPS project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) + * @version Release:2.6 + * @link http://xoops.org + * @since 2.6.0 * @abstract - * @author Kazumi Ono <on...@xo...> - * @package kernel - * @subpackage database + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. */ abstract class XoopsDatabase { @@ -59,6 +53,9 @@ * set the prefix for tables in the database * * @param string $value table prefix + * + * @return this does not return a value + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. */ public function setPrefix($value) { @@ -66,15 +63,19 @@ } /** + * public function prefix($tablename = '') + * * attach the prefix.'_' to a given tablename * if tablename is empty, only prefix will be returned * * @param string $tablename tablename * * @return string prefixed tablename, just prefix if tablename is empty + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. */ public function prefix($tablename = '') { + if ($tablename != '') { return $this->prefix . '_' . $tablename; } else { @@ -83,148 +84,242 @@ } /** + * connect to the database + * + * @param bool $selectdb select the database now? + * + * @return bool successful? + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract * - * @param bool $selectdb - * - * @return void */ - abstract function connect($selectdb = true); + abstract public function connect($selectdb = true); /** - * @param $sequence + * generate an ID for a new row * + * This is for compatibility only. Will always return 0, because MySQL supports + * autoincrement for primary keys. + * + * @param string $sequence name of the sequence from which to get the next ID + * + * @return int always 0, because mysql has support for autoincrement + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function genId($sequence); + abstract public function genId($sequence); /** - * @param $result + * Get a result row as an enumerated array * + * @param resource $result resource to get result from + * + * @return array + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function fetchRow($result); + abstract public function fetchRow($result); /** - * @param $result + * Fetch a result row as an associative array * + * @param resource $result resource to get result from + * * @return array + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function fetchArray($result); + abstract public function fetchArray($result); /** - * @param $result + * Fetch a result row as an associative array * + * @param resource $result resource to get result from + * + * @return array + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function fetchBoth($result); + abstract public function fetchBoth($result); /** - * @param $result + * Fetch a result row as an object * + * @param resource $result resource to get result from + * + * @return object|stdClass + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function fetchObject($result); + abstract public function fetchObject($result); /** + * Get the ID generated from the previous INSERT operation + * + * @return int + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function getInsertId(); + abstract public function getInsertId(); /** - * @param $result + * Get number of rows in result * + * @param resource $result the resource containing the number of rows + * + * @return int the number of rows to return + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function getRowsNum($result); + abstract public function getRowsNum($result); /** + * Get number of affected rows + * + * @return int + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function getAffectedRows(); + abstract public function getAffectedRows(); /** + * Close MySQL connection + * + * @return void + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function close(); + abstract public function close(); /** - * @param $result + * Free all memory associated with the result identifier result. * + * @param resource $result query result + * + * @return bool TRUE on success or FALSE on failure. + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function freeRecordSet($result); + abstract public function freeRecordSet($result); /** + * Returns the text of the error message from previous MySQL operation + * + * @return bool Returns the error text from the last MySQL function, + * or '' (the empty string) if no error occurred. + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function error(); + abstract public function error(); /** + * Returns the numerical value of the error message from previous + * MySQL operation + * + * @return int Returns the error number from the last MySQL function + * , or 0 (zero) if no error occurred. + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function errno(); + abstract public function errno(); /** - * @param $str + * Returns escaped string text with single + * quotes around it to be safely stored in database * + * @param string $str unescaped string text + * + * @return string escaped string text with single quotes around + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function quoteString($str); + abstract public function quoteString($str); /** - * @param $string + * Quotes a string for use in a query. * + * @param string $string string to quote + * + * @return string + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function quote($string); + abstract public function quote($string); /** - * @param $sql - * @param int $limit - * @param int $start + * perform a query on the database * + * @param string $sql a valid MySQL query + * @param int $limit number of records to return + * @param int $start offset of first record to return + * + * @return bool|resource query result or FALSE if successful + * or TRUE if successful and no result + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function queryF($sql, $limit = 0, $start = 0); + abstract public function queryF($sql, $limit = 0, $start = 0); /** - * @param $sql - * @param int $limit - * @param int $start + * perform a query * + * This method is empty and does nothing! It should therefore only be + * used if nothing is exactly what you want done! ;-) + * + * @param string $sql a valid MySQL query + * @param int $limit number of records to return + * @param int $start offset of first record to return + * + * @return this returns nothing + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function query($sql, $limit = 0, $start = 0); + abstract public function query($sql, $limit = 0, $start = 0); /** - * @param $file + * perform queries from SQL dump file in a batch * + * @param string $file file path to an SQL dump file + * + * @return bool FALSE if failed reading SQL file or TRUE + * if the file has been read and queries executed + * @deprecated since version 2.6.0 - alpha 3 * @abstract */ - abstract function queryFromFile($file); + abstract public function queryFromFile($file); /** - * @param $result - * @param $offset + * Get field name * + * @param resource $result query result + * @param int $offset numerical field index + * + * @return string + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function getFieldName($result, $offset); + abstract public function getFieldName($result, $offset); /** - * @param $result - * @param $offset + * Get field type * + * @param resource $result query result + * @param int $offset numerical field index + * + * @return string + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function getFieldType($result, $offset); + abstract public function getFieldType($result, $offset); /** - * @param $result + * Get number of fields in result * + * @param resource $result query result + * + * @return int + * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. * @abstract */ - abstract function getFieldsNum($result); -} \ No newline at end of file + abstract public function getFieldsNum($result); +} Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/databasefactory.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -1,26 +1,30 @@ <?php /* - You may not change or alter any portion of this comment or credits - of supporting developers from this source code or any supporting source code - which is considered copyrighted (c) material of the original comment or credit authors. + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. - 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. -*/ + 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. + */ /** - * Factory Class for XOOPS Database + * XoopsDatabaseFactory class * - * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ - * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package class - * @subpackage database - * @version $Id$ + * PHP version 5.3 + * + * @category Xoops\Class\Database\Databasefactory + * @package DatabaseFactory + * @author Kazumi Ono <on...@xo...> + * @author readheadedrod <red...@ho...> + * @copyright 2013 The XOOPS project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) + * @version Release:2.6 + * @link http://xoops.org + * @since 2.6.0 */ -defined('XOOPS_ROOT_PATH') or die('Restricted access'); - class XoopsDatabaseFactory { @@ -30,33 +34,55 @@ * if the class has not been instantiated yet, this will also take * care of that * + * NOTE: Persistance connection is not included. XOOPS_DB_PCONNECT is ignored. + * allowWebChanges also needs to be addressed + * * @static * @staticvar XoopsDatabase The only instance of database class + * * @return XoopsDatabase Reference to the only instance of database class */ - static function getDatabaseConnection() + public static function getDatabaseConnection() { + global $xoopsDB; static $instance; if (!isset($instance)) { - if (XoopsLoad::fileExists($file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php')) { - require_once $file; - + //New database connector + $config = new \Doctrine\DBAL\Configuration(); + $connectionParams = array( + 'dbname' => XOOPS_DB_NAME, + 'user' => XOOPS_DB_USER, + 'password' => XOOPS_DB_PASS, + 'host' => XOOPS_DB_HOST, +// 'port' => '', +// 'unix_socket' => '', + 'charset' => XOOPS_DB_CHARSET, + 'driver' => 'pdo_mysql', + 'wrapperClass' => 'XoopsConnection', +// 'driverOptions' => array('') + ); + $instance + = \Doctrine\DBAL\DriverManager::getConnection( + $connectionParams, + $config + ); + // Legacy support + if (isset($instance)) { + include_once XOOPS_ROOT_PATH . '/class/database/mysqldatabase.php'; if (!defined('XOOPS_DB_PROXY')) { $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseSafe'; } else { $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseProxy'; } - $xoopsPreload = XoopsPreload::getInstance(); $xoopsPreload->triggerEvent('core.class.database.databasefactory.connection', array(&$class)); - /* @var $instance XoopsDatabase */ - $instance = new $class(); - $instance->setPrefix(XOOPS_DB_PREFIX); - if (!$instance->connect()) { - trigger_error('notrace:Unable to connect to database', E_USER_ERROR); - } + $xoopsDB = new $class(); + $xoopsDB->setPrefix(XOOPS_DB_PREFIX); + $xoopsDB->conn = $instance; } else { - trigger_error('notrace:Failed to load database of type: ' . XOOPS_DB_TYPE . ' in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING); + $xoopsDB = null; + $xoopsPreload = XoopsPreload::getInstance(); + $xoopsPreload->trigger_error('notrace:Unable to connect to database', E_USER_ERROR); } } return $instance; @@ -68,13 +94,18 @@ * * @static * @staticvar XoopsDatabase The only instance of database class + * * @return XoopsDatabase Reference to the only instance of database class + * @depreciated do not use for anything. Will be removed when dependencies are removed from installer. */ - static function getDatabase() + public static function getDatabase() { static $database; if (!isset($database)) { - if (XoopsLoad::fileExists($file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php')) { + if (XoopsLoad::fileExists( + $file = XOOPS_ROOT_PATH . '/class/database/' + . XOOPS_DB_TYPE . 'database.php' + )) { include_once $file; if (!defined('XOOPS_DB_PROXY')) { $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseSafe'; @@ -84,9 +115,9 @@ unset($database); $database = new $class(); } else { - trigger_error('notrace:Failed to load database of type: ' . XOOPS_DB_TYPE . ' in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING); + trigger_error('notrace:Database Failed in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING); } } return $database; } -} \ No newline at end of file +} Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/manager.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/manager.php 2013-08-27 22:17:02 UTC (rev 11987) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/database/manager.php 2013-08-28 02:02:20 UTC (rev 11988) @@ -1,340 +1,381 @@ -<?php -/* - You may not change or alter any portion of this comment or credits - of supporting developers from this source code or any supporting source code - which is considered copyrighted (c) material of the original comment or credit authors. - - 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. -*/ - -/** - * Database manager for XOOPS - * - * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ - * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) - * @package class - * @subpackage database - * @since 2.6.0 - * @author Haruki Setoyama <ha...@pl...> - * @version $Id$ - */ - -class XoopsDatabaseManager -{ - /** - * @var array - */ - private $s_tables = array(); - - /** - * @var array - */ - private $f_tables = array(); - - /** - * @var XoopsDatabase - */ - public $db; - - /** - * @var array - */ - public $successStrings = array(); - - /** - * @var array - */ - public $failureStrings = array(); - - /** - * - */ - public function __construct() - { - $xoops = Xoops::getInstance(); - $this->db = $xoops->db(); - $this->db->setPrefix(XOOPS_DB_PREFIX); - $this->successStrings = array( - 'create' => XoopsLocale::SF_TABLE_CREATED, - 'insert' => XoopsLocale::SF_ENTRIES_INSERTED_TO_TABLE, - 'alter' => XoopsLocale::SF_TABLE_UPDATED, - 'drop' => XoopsLocale::SF_TABLE_DROPPED, - ); - $this->failureStrings = array( - 'create' => XoopsLocale::EF_TABLE_NOT_CREATED, - 'insert' => XoopsLocale::EF_ENTRIES_NOT_INSERTED_TO_TABLE, - 'alter' => XoopsLocale::EF_TABLE_NOT_UPDATED, - 'drop' => XoopsLocale::EF_TABLE_NOT_DROPPED, - ); - } - - /** - * @return bool - */ - public function isConnectable() - { - return ($this->db->connect(false) != false) ? true : false; - } - - /** - * @return bool - */ - public function dbExists() - { - return ($this->db->connect() != false) ? true : false; - } - - /** - * @return bool - */ - public function createDB() - { - $this->db->connect(false); - - $result = $this->db->query("CREATE DATABASE " . XOOPS_DB_NAME); - - return ($result != false) ? true : false; - } - - /** - * @param string $sql_file_path - * @param bool $force - * - * @return bool - */ - public function queryFromFile($sql_file_path, $force = false) - { - if (!XoopsLoad::fileExists($sql_file_path)) { - return false; - } - $queryFunc = (bool)$force ? "queryF" : "query"; - $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path))); - SqlUtility::splitMySqlFile($pieces, $sql_query); - $this->db->connect(); - foreach ($pieces as $piece) { - $piece = trim($piece); - // [0] contains the prefixed query - // [4] contains unprefixed table name - $prefixed_query = SqlUtility::prefixQuery($piece, $this->db->prefix()); - if ($prefixed_query != false) { - $table = $this->db->prefix($prefixed_query[4]); - if ($prefixed_query[1] == 'CREATE TABLE') { - if ($this->db->$queryFunc($prefixed_query[0]) != false) { - if (!isset($this->s_tables['create'][$table])) { - $this->s_tables['create'][$table] = 1; - } - } else { - if (!isset($this->f_tables['create'][$table])) { - $this->f_tables['create'][$table] = 1; - } - } - } else { - if ($prefixed_query[1] == 'INSERT INTO') { - if ($this->db->$queryFunc($prefixed_query[0]) != false) { - if (!isset($this->s_tables['insert'][$table])) { - $this->s_tables['insert'][$table] = 1; - } else { - $this->s_tables['insert'][$table]++; - } - } else { - if (!isset($this->f_tables['insert'][$table])) { - $this->f_tables['insert'][$table] = 1; - } else { - $this->f_tables['insert'][$table]++; - } - } - } else { - if ($prefixed_query[1] == 'ALTER TABLE') { - if ($this->db->$queryFunc($prefixed_query[0]) != false) { - if (!isset($this->s_tables['alter'][$table])) { - $this->s_tables['alter'][$table] = 1; - } - } else { - if (!isset($this->s_tables['alter'][$table])) { - $this->f_tables['alter'][$table] = 1; - } - } - } else { - if ($prefixed_query[1] == 'DROP TABLE') { - if ($this->db->$queryFunc('DROP TABLE ' . $table) != false) { - if (!isset($this->s_tables['drop'][$table])) { - $this->s_tables['drop'][$table] = 1; - } - } else { - if (!isset($this->s_tables['drop'][$table])) { - $this->f_tables['drop'][$table] = 1; - } - } - } - } - } - } - } - } - return true; - } - - /** - * @return string - */ - public function report() - { - $commands = array('create', 'insert', 'alter', 'drop'); - $content = '<ul class="log">'; - foreach ($commands as $cmd) { - if (!@empty($this->s_tables[$cmd])) { - foreach ($this->s_tables[$cmd] as $key => $val) { - $content .= '<li class="success">'; - $content .= ($cmd != 'insert') ? sprintf($this->successStrings[$cmd], $key) : sprintf($this->successStrings[$cmd], $val, $key); - $content .= "</li>\n"; - } - } - } - foreach ($commands as $cmd) { - if (!@empty($this->f_tables[$cmd])) { - foreach ($this->f_tables[$cmd] as $key => $val) { - $content .= '<li class="failure">'; - $content .= ($cmd != 'insert') ? sprintf($this->failureStrings[$cmd], $key) : sprintf($this->failureStrings[$cmd], $val, $key); - $content .= "</li>\n"; - } - } - } - $content .= '</ul>'; - return $content; - } - - /** - * @param string $sql - * - * @return mixed - */ - public function query($sql) - { - $this->db->connect(); - return $this->db->query($sql); - } - - /** - * @param $table - * - * @return string - */ - public function prefix($table) - { - $this->db->connect(); - return $this->db->prefix($table); - } - - /** - * @param $ret - * - * @return array - */ - public function fetchArray($ret) - { - $this->db->connect(); - return $this->db->fetchArray($ret); - } - - /** - * @param $table - * @param $query - * - * @return bool|void - */ - public function insert($table, $query) - { - $this->db->connect(); - $table = $this->db->prefix($table); - $query = 'INSERT INTO ' . $table . ' ' . $query; - if (!$this->db->queryF($query)) { - if (!isset($this->f_tables['insert'][$table])) { - $this->f_tables['insert'][$table] = 1; - } else { - $this->f_tables['insert'][$table]++; - } - return false; - } else { - if (!isset($this->s_tables['insert'][$table])) { - $this->s_tables['insert'][$table] = 1; - } else { - $this->s_tables['insert'][$table]++; - } - return $this->db->getInsertId(); - } - } - - /** - * @return bool - */ - public function isError() - { - return (isset($this->f_tables)) ? true : false; - } - - /** - * @param $tables - * - * @return array - */ - public function deleteTables($tables) - { - $deleted = array(); - $this->db->connect(); - foreach ($tables as $key => $val) { - if (!$this->db->query("DROP TABLE " . $this->db->prefix($key))) { - $deleted[] = $val; - } - } - return $deleted; - } - - /** - * @param $table - * - * @return bool - */ - public function tableExists($table) - { - $table = trim($table); - $ret = false; - if ($table != '') { - $this->db->connect(); - $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix($table); - $ret = (false != $this->db->query($sql)) ? true : false; - } - return $ret; - } - - /** - * This method allows to copy fields from one table to another - * - * @param array $fieldsMap Map of the fields - * ex: array('oldfieldname' => 'newfieldname'); - * @param string $oTableName Old Table - * @param string $nTableName New Table - * @param bool $dropTable Drop old Table - */ - public function copyFields($fieldsMap, $oTableName, $nTableName, $dropTable = false) - { - $sql = "SHOW COLUMNS FROM " . $this->db->prefix($oTableName); - $result = $this->db->queryF($sql); - if (($rows = $this->db->getRowsNum($result)) == count($fieldsMap)) { - $sql = "SELECT * FROM " . $this->db->prefix($oTableName); - $result = $this->db->queryF($sql); - while ($myrow = $this->db->fetchArray($result)) { - ksort($fieldsMap); - ksort($myrow); - $sql = "INSERT INTO `" . $this->db->prefix($nTableName) . "` " . "(`" . implode("`,`", $fieldsMap) . "`)" . " VALUES ('" . implode("','", $myrow) . "')"; - - $this->db->queryF($sql); - } - if ($dropTable) { - $sql = "DROP TABLE " . $this->db->prefix($oTableName); - $this->db->queryF($sql); - } - } - } -} \ No newline at end of file +<?php +/** + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. + */ + +/** + * Database manager for XOOPS + * + * PHP version 5.3 + * + * @category Xoops\Class\Database\Manager + * @package Manager + * @author Haruki Setoyama <ha...@pl...> + * @copyright 2013 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) + * @version Release: 2.6 + * @link http://xoops.org + * @since 2.6.0 + */ + +class XoopsDatabaseManager +{ + /** + * @var array + */ + private $s_tables = array(); + + /** + * @var array + */ + private $f_tables = array(); + + /** + * @var XoopsDatabase + */ + public $db; + + /** + * @var array + */ + public $successStrings = array(); + + /** + * @var array + */ + public $failureStrings = array(); + + /** + *Construct declaration + */ + public function __construct() + { + $xoops = Xoops::getInstance(); + $xoops->db(); + global $xoopsDB; + $this->db = $xoopsDB; + $this->db->setPrefix(XOOPS_DB_PREFIX); + $this->successStrings = array( + 'create' => XoopsLocale::SF_TABLE_CREATED, + 'insert' => XoopsLocale::SF_ENTRIES_INSERTED_TO_TABLE, + 'alter' => XoopsLocale::SF_TABLE_UPDATED, + 'drop' => XoopsLocale::SF_TABLE_DROPPED, + ); + $this->failureStrings = array( + 'create' => XoopsLocale::EF_TABLE_NOT_CREATED, + 'insert' => XoopsLocale::EF_ENTRIES_NOT_INSERTED_TO_TABLE, + 'alter' => XoopsLocale::EF_TABLE_NOT_UPDATED, + 'drop' => XoopsLocale::EF_TABLE_NOT_DROPPED, + ); + } + + /** + * Is the database connectable? + * + * @return bool is it connectable? + */ + public function isConnectable() + { + return ($this->db->connect(false) != false) ? true : false; + } + + /** + * Checks if a database exists + * + * @return bool returns if exists + */ + public function dbExists() + { + return ($this->db->connect() != false) ? true : false; + } + + /** + * creates a database table + * + * @return bool return if successful + */ + public function createDB() + { + $this->db->connect(false); + + $result = $this->db->query("CREATE DATABASE " . XOOPS_DB_NAME); + + return ($result != false) ? true : false; + } + + /** + * Loads a query from a file + * + * @param string $sql_file_path name of file to read + * @param bool $force weither to force the query or not + * + * @return bool + */ + public function queryFromFile($sql_file_path, $force = false) + { + if (!XoopsLoad::fileExists($sql_file_path)) { + return false; + } + $queryFunc = (bool)$force ? "queryF" : "query"; + $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path))); + SqlUtility::splitMySqlFile($pieces, $sql_query); + $this->db->connect(); + foreach ($pieces as $piece) { + $piece = trim($piece); + // [0] contains the prefixed query + // [4] contains unprefixed table name + $prefixed_query = SqlUtility::prefixQuery($piece, $this->db->prefix()); + if ($prefixed_query != false) { + $table = $this->db->prefix($prefixed_query[4]); + if ($prefixed_query[1] == 'CREATE TABLE') { + if ($this->db->$queryFunc($prefixed_query[0]) != false) { + if (!isset($this->s_tables['create'][$table])) { + $this->s_tables['create'][$table] = 1; + } + } else { + if (!isset($this->f_tables['create'][$table])) { + $this->f_tables['create'][$table] = 1; + } + } + } else { + if ($prefixed_query[1] == 'INSERT INTO') { + if ($this->db->$queryFunc($prefixed_query[0]) != false) { + if (!isset($this->s_tables['insert'][$table])) { + $this->s_tables['insert'][$table] = 1; + } else { + $this->s_tables['insert'][$table]++; + } + } else { + if (!isset($this->f_tables['insert'][$table])) { + $this->f_tables['insert'][$table] = 1; + } else { + $this->f_tables['insert'][$table]++; + } + } + } else { + if ($prefixed_query[1] == 'ALTER TABLE') { + if ($this->db->$queryFunc($prefixed_query[0]) != false) { + if (!isset($this->s_tables['alter'][$table])) { + $this->s_tables['alter'][$table] = 1; + } + } else { + if (!isset($this->s_tables['alter'][$table])) { + $this->f_tables['alter'][$table] = 1; + } + } + } else { + if ($prefixed_query[1] == 'DROP TABLE') { + if ($this->db->$queryFunc('DROP TABLE ' . $table) != false) { + if (!isset($this->s_tables['drop'][$table])) { + $this->s_tables['drop'][$table] = 1; + } + } else { + if (!isset($this->s_tables['drop'][$table])) { + $this->f_tables['drop'][$table] = 1; + } + } + } + } + } + } + } + } + return true; + } + + /** + * returns a report + * + * @return string + */ + public function report() + { + $commands = array('create', 'insert', 'alter', 'drop'); + $content = '<ul class="log">'; + foreach ($commands as $cmd) { + if (!@empty($this->s_tables[$cmd])) { + foreach ($this->s_tables[$cmd] as $key => $val) { + $content .= '<li class="success">'; + $content .= ($cmd != 'insert') + ? sprintf($this->successStrings[$cmd], $key) + : sprintf($this->successStrings[$cmd], $val, $key); + $content .= "</li>\n"; + } + } + } + foreach ($commands as $cmd) { + if (!@empty($this->f_tables[$cmd])) { + foreach ($this->f_tables[$cmd] as $key => $val) { + $content .= '<li class="failure">'; + $content .= ($cmd != 'insert') + ? sprintf($this->failureStrings[$cmd], $key) + : sprintf($this->failureStrings[$cmd], $val, $key); + $content .= "</li>\n"; + } + } + } + $content .= '</ul>'; + return $content; + } + + /** + * runs a query + * + * @param string $sql sql statement to perform + * + * @return mixed + */ + public function query($sql) + { + $this->db->connect(); + return $this->db->query($sql); + } + + /** + * Setup prefix table + * + * @param string $table table to prefix + * + * @return string prefixed table + */ + public function prefix($table) + { + $this->db->connect(); + return $this->db->prefix($table); + } + + /** + * fetches an array + * + * @param string $ret resource that was returned from query + * + * @return array returns the array + */ + public function fetchArray($ret) + { + $this->db->connect(); + return $this->db->fetchArray($ret); + } + + /** + * Inserts into a table + * + * @param string $table table to insert into + * @param string $query query to use to insert + * + * @return bool|void + */ + public function insert($table, $query) + { + $this->db->connect(); + $table = $this->db->prefix($table); + $query = 'INSERT INTO ' . $table . ' ' . $query; + if (!$this->db->qu... [truncated message content] |