<commit_before><?php 
/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
 * @license    http://www.pimcore.org/license     New BSD License
 */

class Pimcore_Resource_Wrapper {

    /**
     * @var Zend_Db_Adapter_Abstract
     */
    protected $resource;

    /**
     * use a seperate connection for DDL queries to avoid implicit commits
     * @var Zend_Db_Adapter_Abstract
     */
    protected $DDLResource;

    /**
     * @param \Zend_Db_Adapter_Abstract $DDLResource
     */
    public function setDDLResource($DDLResource)
    {
        $this->DDLResource = $DDLResource;
        return $this;
    }

    /**
     * @return \Zend_Db_Adapter_Abstract
     */
    public function getDDLResource()
    {
        if(!$this->DDLResource) {
            // get the Zend_Db_Adapter_Abstract not the wrapper
            $this->DDLResource = Pimcore_Resource::getConnection(true);
        }
        return $this->DDLResource;
    }

    /**
     *
     */
    public function closeDDLResource() {
        $this->closeConnectionResource($this->DDLResource);
    }

    /**
     * @param $resource
     */
    public function __construct($resource = false) {
        if($resource) {
            $this->setResource($resource);
        }
    }

    /**
     * @param $resource
     * @return void
     */
    public function setResource($resource)
    {
        $this->resource = $resource;
        return $this;
    }

    /**
     * @return Zend_Db_Adapter_Abstract
     */
    public function getResource()
    {
        if(!$this->resource) {
            // get the Zend_Db_Adapter_Abstract not the wrapper
            $this->resource = Pimcore_Resource::getConnection(true);
        }
        return $this->resource;
    }

    /**
     *
     */
    public function closeResource() {
        $this->closeConnectionResource($this->resource);
    }

    /**
     * @param Zend_Db_Adapter_Abstract $resource
     */
    protected function closeConnectionResource($resource) {
        if($resource) {
            try {
                $connectionId = null;

                // unfortunately mysqli doesn't throw an exception in the case the connection is lost (issues a warning)
                // and when sending a query to the broken connection (eg. when forking)
                // so we have to handle mysqli and pdo_mysql differently
                if($resource instanceof Zend_Db_Adapter_Mysqli) {
                    $connectionId = $this->resource->getConnection()->thread_id;
                } else if ($resource instanceof Zend_Db_Adapter_Pdo_Mysql) {
                    $connectionId = $resource->fetchOne("SELECT CONNECTION_ID()");
                }
                Logger::debug(get_class($resource) . ": closing mysql connection with ID: " . $connectionId);

                $this->resource->closeConnection();
                $this->resource = null;
            } catch (\Exception $e) {
                // this is the case when the mysql connection has gone away (eg. when forking using pcntl)
                Logger::info($e);
            }
        }
    }


    /**
     * insert on dublicate key update extension to the Zend_Db Adapter
     * @param $table
     * @param array $data
     * @return mixed
     * @throws Zend_Db_Adapter_Exception
     */
    public function insertOrUpdate($table, array $data)<commit_msg>PIMCORE-1918 - maintenance.php: Error while sending STMT_PREPARE/STMT_CLOSE packet<commit_after><?php 
/**
 * Pimcore
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.pimcore.org/license
 *
 * @copyright  Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
 * @license    http://www.pimcore.org/license     New BSD License
 */

class Pimcore_Resource_Wrapper {

    /**
     * @var Zend_Db_Adapter_Abstract
     */
    protected $resource;

    /**
     * use a seperate connection for DDL queries to avoid implicit commits
     * @var Zend_Db_Adapter_Abstract
     */
    protected $DDLResource;

    /**
     * @param \Zend_Db_Adapter_Abstract $DDLResource
     */
    public function setDDLResource($DDLResource)
    {
        $this->DDLResource = $DDLResource;
        return $this;
    }

    /**
     * @return \Zend_Db_Adapter_Abstract
     */
    public function getDDLResource()
    {
        if(!$this->DDLResource) {
            // get the Zend_Db_Adapter_Abstract not the wrapper
            $this->DDLResource = Pimcore_Resource::getConnection(true);
        }
        return $this->DDLResource;
    }

    /**
     *
     */
    public function closeDDLResource() {
        $this->closeConnectionResource($this->DDLResource);
        $this->DDLResource = null;
    }

    /**
     * @param $resource
     */
    public function __construct($resource = false) {
        if($resource) {
            $this->setResource($resource);
        }
    }

    /**
     * @param $resource
     * @return void
     */
    public function setResource($resource)
    {
        $this->resource = $resource;
        return $this;
    }

    /**
     * @return Zend_Db_Adapter_Abstract
     */
    public function getResource()
    {
        if(!$this->resource) {
            // get the Zend_Db_Adapter_Abstract not the wrapper
            $this->resource = Pimcore_Resource::getConnection(true);
        }
        return $this->resource;
    }

    /**
     *
     */
    public function closeResource() {
        $this->closeConnectionResource($this->resource);
        $this->resource = null;
    }

    /**
     * @param Zend_Db_Adapter_Abstract $resource
     */
    protected function closeConnectionResource($resource) {
        if($resource) {
            try {
                $connectionId = null;

                // unfortunately mysqli doesn't throw an exception in the case the connection is lost (issues a warning)
                // and when sending a query to the broken connection (eg. when forking)
                // so we have to handle mysqli and pdo_mysql differently
                if($resource instanceof Zend_Db_Adapter_Mysqli) {
                    if($resource->getConnection()) {
                        $connectionId = $resource->getConnection()->thread_id;
                    }
                } else if ($resource instanceof Zend_Db_Adapter_Pdo_Mysql) {
                    $connectionId = $resource->fetchOne("SELECT CONNECTION_ID()");
                }
                Logger::debug(get_class($resource) . ": closing mysql connection with ID: " . $connectionId);

                $resource->closeConnection();
            } catch (\Exception $e) {
                // this is the case when the mysql connection has gone away (eg. when forking using pcntl)
                Logger::info($e);
            }
        }
    }


    /**
     * insert on dublicate key update extension to the Zend_Db Adapter
     * @param $table
     * @param array $data
     * @return mixed
     * @throws Zend_Db_Adapter_Exception
     */
    public function insertOrUpdate($table, array $data)
{'fraction_non_alphanumeric': 0.10525608280682887, 'fraction_numerical': 0.0026885334050275574, 'mean_word_length': 2.004846526655897, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4656252', 'n_tokens_mistral': 2112, 'n_tokens_neox': 2000, 'n_words': 514}