]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'hackfest' into nightly
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 6 Jun 2015 20:15:39 +0000 (22:15 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 6 Jun 2015 20:15:39 +0000 (22:15 +0200)
classes/File.php
classes/GS_DataObject.php
classes/Managed_DataObject.php
classes/Memcached_DataObject.php
classes/Safe_DataObject.php
classes/Status_network_tag.php
extlib/DB/DataObject.php

index d4abbfddeef3f5f45c26621fce6414c16e75827f..1a29ea5107e537dec350188c4b7b323e523b2e76 100644 (file)
@@ -488,13 +488,13 @@ class File extends Managed_DataObject
             throw new ServerException('URL already exists in DB');
         }
         $sql = 'UPDATE %1$s SET urlhash=%2$s, url=%3$s WHERE urlhash=%4$s;';
-        $result = $this->query(sprintf($sql, $this->__table,
+        $result = $this->query(sprintf($sql, $this->tableName(),
                                              $this->_quote((string)self::hashurl($url)),
                                              $this->_quote((string)$url),
                                              $this->_quote((string)$this->urlhash)));
         if ($result === false) {
             common_log_db_error($this, 'UPDATE', __FILE__);
-            throw new ServerException("Could not UPDATE {$this->__table}.url");
+            throw new ServerException("Could not UPDATE {$this->tableName()}.url");
         }
 
         return $result;
index 67f324049324b7affacf3f44c21d43477ef91e46..4ca2436eec8df941c44f141e3becaf8e9fb94350 100644 (file)
@@ -59,7 +59,7 @@ class GS_DataObject extends DB_DataObject
         return $res;
     }
 
-    public function debugLevel($v = null)
+    static public function debugLevel($v = null)
     {
         // avoid those annoying PEAR::DB strict standards warnings it causes
         $old = error_reporting();
@@ -72,7 +72,21 @@ class GS_DataObject extends DB_DataObject
         return $res;
     }
 
-    public function factory($table = '')
+    // delete calls PEAR::isError from DB_DataObject, so let's make that disappear too
+    public function delete($useWhere = false)
+    {
+        // avoid those annoying PEAR::DB strict standards warnings it causes
+        $old = error_reporting();
+        error_reporting(error_reporting() & ~E_STRICT);
+
+        $res = parent::delete($useWhere);
+
+        // reset
+        error_reporting($old);
+        return $res;
+    }
+
+    static public function factory($table = '')
     {
         // avoid those annoying PEAR::DB strict standards warnings it causes
         $old = error_reporting();
@@ -137,6 +151,34 @@ class GS_DataObject extends DB_DataObject
         return $res;
     }
 
+    // insert calls PEAR::isError from DB_DataObject, so let's make that disappear too
+    public function insert()
+    {
+        // avoid those annoying PEAR::DB strict standards warnings it causes
+        $old = error_reporting();
+        error_reporting(error_reporting() & ~E_STRICT);
+
+        $res = parent::insert();
+
+        // reset
+        error_reporting($old);
+        return $res;
+    }
+
+    // DB_DataObject's joinAdd calls DB_DataObject::factory explicitly, so our factory-override doesn't work
+    public function joinAdd($obj = false, $joinType='INNER', $joinAs=false, $joinCol=false)
+    {
+        // avoid those annoying PEAR::DB strict standards warnings it causes
+        $old = error_reporting();
+        error_reporting(error_reporting() & ~E_STRICT);
+
+        $res = parent::joinAdd($obj, $joinType, $joinAs, $joinCol);
+
+        // reset
+        error_reporting($old);
+        return $res;
+    }
+
     public function links()
     {
         // avoid those annoying PEAR::DB strict standards warnings it causes
@@ -164,7 +206,7 @@ class GS_DataObject extends DB_DataObject
         return $res;
     }
 
-    public function staticGet($class, $k, $v = null)
+    static public function staticGet($class, $k, $v = null)
     {
         // avoid those annoying PEAR::DB strict standards warnings it causes
         $old = error_reporting();
index a69a957bcc0225bad8b4085312b1b73a53b9ea13..ec514029939547997f5e098925e79816868d0034 100644 (file)
@@ -406,7 +406,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
                 common_log_db_error($this, 'UPDATE', __FILE__);
                 // rollback as something bad occurred
                 $this->query('ROLLBACK');
-                throw new ServerException("Could not UPDATE non-keys for {$this->__table}");
+                throw new ServerException("Could not UPDATE non-keys for {$this->tableName()}");
             }
             $orig->decache();
             $this->encache();
@@ -428,7 +428,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
             common_log_db_error($this, 'UPDATE', __FILE__);
             // rollback as something bad occurred
             $this->query('ROLLBACK');
-            throw new ServerException("Could not UPDATE key fields for {$this->__table}");
+            throw new ServerException("Could not UPDATE key fields for {$this->tableName()}");
         }
 
         // Update non-keys too, if the previous endeavour worked.
@@ -438,7 +438,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
             common_log_db_error($this, 'UPDATE', __FILE__);
             // rollback as something bad occurred
             $this->query('ROLLBACK');
-            throw new ServerException("Could not UPDATE non-keys for {$this->__table}");
+            throw new ServerException("Could not UPDATE non-keys for {$this->tableName()}");
         }
         $orig->decache();
         $this->encache();
index c725e1d9aa1754f5ab2488f9db2052079710450c..c1f6f644db010d9e85e4d121b73474f3cb547724 100644 (file)
@@ -461,11 +461,11 @@ class Memcached_DataObject extends Safe_DataObject
         }
 
         global $_DB_DATAOBJECT;
-        if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
+        if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"])) {
             $this->databaseStructure();
 
         }
-        return $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
+        return $_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"];
     }
 
     function encache()
@@ -836,7 +836,7 @@ class Memcached_DataObject extends Safe_DataObject
         if (!$dsn) {
 
             if (!$this->_database) {
-                $this->_database = isset($options["table_{$this->__table}"]) ? $options["table_{$this->__table}"] : null;
+                $this->_database = isset($options["table_{$this->tableName()}"]) ? $options["table_{$this->tableName()}"] : null;
             }
 
             if ($this->_database && !empty($options["database_{$this->_database}"]))  {
index 8e5e72c013bdc6ebe7d68cada500fb408e294efa..6aed88ae1f67501d1e1af30ffe6995b0cc469f70 100644 (file)
@@ -186,7 +186,7 @@ class Safe_DataObject extends GS_DataObject
 
             // database loaded - but this is table is not available..
             if (
-                    empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])
+                    empty($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()])
                     && !empty($_DB_DATAOBJECT['CONFIG']['proxy'])
                 ) {
                 if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
@@ -197,7 +197,7 @@ class Safe_DataObject extends GS_DataObject
 
 
                 $x = new DB_DataObject_Generator;
-                $x->fillTableSchema($this->_database,$this->__table);
+                $x->fillTableSchema($this->_database,$this->tableName());
             }
             return true;
         }
@@ -225,7 +225,7 @@ class Safe_DataObject extends GS_DataObject
 
         // now have we loaded the structure..
 
-        if (!empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])) {
+        if (!empty($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()])) {
             return true;
         }
         // - if not try building it..
@@ -234,11 +234,11 @@ class Safe_DataObject extends GS_DataObject
                 require_once 'DB/DataObject/Generator.php';
 
             $x = new DB_DataObject_Generator;
-            $x->fillTableSchema($this->_database,$this->__table);
+            $x->fillTableSchema($this->_database,$this->tableName());
             // should this fail!!!???
             return true;
         }
-        $this->debug("Cant find database schema: {$this->_database}/{$this->__table} \n".
+        $this->debug("Cant find database schema: {$this->_database}/{$this->tableName()} \n".
                     "in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5);
         // we have to die here!! - it causes chaos if we don't (including looping forever!)
         // Low level exception. No need for i18n as discussed with Brion.
index 9e5ff89be352c9863d72a977756c8445ae5da7ea..b45224ff74c5225b02fa23c21d10269c9ba65d22 100644 (file)
@@ -38,7 +38,7 @@ class Status_network_tag extends Safe_DataObject
         $sn = new Status_network();
         $sn->_connect();
 
-        $config['db']['table_'. $this->__table] = $sn->_database;
+        $config['db']['table_'. $this->tableName()] = $sn->_database;
 
         $this->_connect();
     }
index 684a98c92a4c3a1e42edf8ba37ac88a5d4eb20e7..1a7b34665d174224ef50528dd4355b9e348cbdf7 100755 (executable)
@@ -346,7 +346,7 @@ class DB_DataObject extends DB_DataObject_Overload
                $this->_query['derive_select']
                .' FROM ( SELECT'.
                     $this->_query['data_select'] . " \n" .
-                    " FROM   $tn \n" .
+                    " FROM   $tn  " . $this->_query['useindex'] . " \n" .
                     $this->_join . " \n" .
                     $this->_query['condition'] . " \n" .
                     $this->_query['group_by'] . " \n" .
@@ -362,7 +362,7 @@ class DB_DataObject extends DB_DataObject_Overload
         
         $sql = 'SELECT ' .
             $this->_query['data_select'] . " \n" .
-            " FROM   $tn \n" .
+            " FROM   $tn  " . $this->_query['useindex'] . " \n" .
             $this->_join . " \n" .
             $this->_query['condition'] . " \n" .
             $this->_query['group_by'] . " \n" .
@@ -862,6 +862,43 @@ class DB_DataObject extends DB_DataObject_Overload
         $this->_query['having'] .= " AND {$having}";
     }
 
+    /**
+     * Adds a using Index
+     *
+     * $object->useIndex(); //reset the use Index 
+     * $object->useIndex("some_index");
+     *
+     * Note do not put unfiltered user input into theis method.
+     * This is mysql specific at present? - might need altering to support other databases.
+     * 
+     * @param  string|array  $index  index or indexes to use.
+     * @access public
+     * @return none|PEAR::Error - invalid args only
+     */
+    function useIndex($index = false)
+    {
+        if ($this->_query === false) {
+            $this->raiseError(
+                "You cannot do two queries on the same object (copy it before finding)", 
+                DB_DATAOBJECT_ERROR_INVALIDARGS);
+            return false;
+        }
+        if ($index=== false) {
+            $this->_query['useindex'] = '';
+            return;
+        }
+        // check input...= 0 or '    ' == error!
+        if ((is_string($index) && !trim($index)) || (is_array($index) && !count($index)) ) {
+            return $this->raiseError("Having: No Valid Arguments", DB_DATAOBJECT_ERROR_INVALIDARGS);
+        }
+        $index = is_array($index) ? implode(', ', $index) : $index;
+        
+        if (!$this->_query['useindex']) {
+            $this->_query['useindex'] = " USE INDEX ({$index}) ";
+            return;
+        }
+        $this->_query['useindex'] =  substr($this->_query['useindex'],0, -2) . ", {$index}) ";
+    }
     /**
      * Sets the Limit
      *
@@ -1090,11 +1127,9 @@ class DB_DataObject extends DB_DataObject_Overload
                 continue;
             }
         
-            
-           
-           
-            // Ignore variables which aren't set to a value
-            if ( (!isset($this->$k) || ($v == 1 && $this->$k == ''))
+             
+            // Ignore INTEGERS which aren't set to a value - or empty string..
+            if ( (!isset($this->$k) || ($v == 1 && $this->$k === ''))
                     && $ignore_null
             ) {
                 continue;
@@ -1342,7 +1377,8 @@ class DB_DataObject extends DB_DataObject_Overload
       
         foreach($items as $k => $v) {
             
-            if ((!isset($this->$k) || ($v == 1 && $this->$k == ''))
+            // I think this is ignoring empty vlalues
+            if ((!isset($this->$k) || ($v == 1 && $this->$k === ''))
                     && $ignore_null
             ) {
                  continue;
@@ -1808,6 +1844,7 @@ class DB_DataObject extends DB_DataObject_Overload
         'group_by'    => '', // the GROUP BY condition
         'order_by'    => '', // the ORDER BY condition
         'having'      => '', // the HAVING condition
+        'useindex'   => '', // the USE INDEX condition
         'limit_start' => '', // the LIMIT condition
         'limit_count' => '', // the LIMIT condition
         'data_select' => '*', // the columns to be SELECTed
@@ -2458,7 +2495,7 @@ class DB_DataObject extends DB_DataObject_Overload
             } else {
                 $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5] = DB::connect($dsn);
             }
-            
+             
         } else {
             /* assumption is MDB2 */
             require_once 'MDB2.php';
@@ -2774,7 +2811,7 @@ class DB_DataObject extends DB_DataObject_Overload
     
     
 
-    function factory($table = '')
+    static function factory($table = '')
     {
         global $_DB_DATAOBJECT;
         
@@ -2792,13 +2829,14 @@ class DB_DataObject extends DB_DataObject_Overload
         }
         // no configuration available for database
         if (!empty($database) && empty($_DB_DATAOBJECT['CONFIG']['database_'.$database])) {
-                return DB_DataObject::raiseError(
+                $do = new DB_DataObject();
+                $do->raiseError(
                     "unable to find database_{$database} in Configuration, It is required for factory with database"
                     , 0, PEAR_ERROR_DIE );   
        }
         
        
-        
+        /*
         if ($table === '') {
             if (is_a($this,'DB_DataObject') && strlen($this->tableName())) {
                 $table = $this->tableName();
@@ -2809,6 +2847,7 @@ class DB_DataObject extends DB_DataObject_Overload
             }
         }
         
+        */
         // does this need multi db support??
         $cp = isset($_DB_DATAOBJECT['CONFIG']['class_prefix']) ?
             explode(PATH_SEPARATOR, $_DB_DATAOBJECT['CONFIG']['class_prefix']) : '';
@@ -2859,7 +2898,8 @@ class DB_DataObject extends DB_DataObject_Overload
         }
         
         if (!$rclass || !class_exists($rclass)) {
-            return DB_DataObject::raiseError(
+            $dor = new DB_DataObject();
+            return $dor->raiseError(
                 "factory could not find class " . 
                 (is_array($class) ? implode(PATH_SEPARATOR, $class)  : $class  ). 
                 "from $table",
@@ -2944,7 +2984,8 @@ class DB_DataObject extends DB_DataObject_Overload
                 }
             }
             if (!$found) {
-                DB_DataObject::raiseError(
+                $dor = new DB_DataObject();
+                $dor->raiseError(
                     "autoload:Could not find class " . implode(',', $cls) .
                     " using class_location value :" . $search .
                     " using include_path value :" . ini_get('include_path'), 
@@ -2965,7 +3006,8 @@ class DB_DataObject extends DB_DataObject_Overload
             }
         }
         if (!$ce) {
-            DB_DataObject::raiseError(
+            $dor = new DB_DataObject();
+            $dor->raiseError(
                 "autoload:Could not autoload " . implode(',', $cls) , 
                 DB_DATAOBJECT_ERROR_INVALIDCONFIG);
             return false;
@@ -3975,6 +4017,7 @@ class DB_DataObject extends DB_DataObject_Overload
         global $_DB_DATAOBJECT;
         $keys  = $this->keys();
         $items = $this->table();
+        
         if (!$items) {
             $this->raiseError(
                 "setFrom:Could not find table definition for {$this->tableName()}", 
@@ -4592,7 +4635,7 @@ class DB_DataObject extends DB_DataObject_Overload
      * @access  public
      * @return  none
      */
-    function debugLevel($v = null)
+    static function debugLevel($v = null)
     {
         global $_DB_DATAOBJECT;
         if (empty($_DB_DATAOBJECT['CONFIG'])) {
@@ -4646,7 +4689,8 @@ class DB_DataObject extends DB_DataObject_Overload
             $error = $message;
         } else {
             require_once 'DB/DataObject/Error.php';
-            $error = PEAR::raiseError($message, $type, $behaviour,
+            $dor = new PEAR();
+            $error = $dor->raiseError($message, $type, $behaviour,
                             $opts=null, $userinfo=null, 'DB_DataObject_Error'
                         );
         }
@@ -4773,7 +4817,7 @@ class DB_DataObject extends DB_DataObject_Overload
     /**
      * (deprecated - use ::get / and your own caching method)
      */
-    function staticGet($class, $k, $v = null)
+    static function staticGet($class, $k, $v = null)
     {
         $lclass = strtolower($class);
         global $_DB_DATAOBJECT;
@@ -4799,7 +4843,8 @@ class DB_DataObject extends DB_DataObject_Overload
 
         $obj = DB_DataObject::factory(substr($class,strlen($_DB_DATAOBJECT['CONFIG']['class_prefix'])));
         if (PEAR::isError($obj)) {
-            DB_DataObject::raiseError("could not autoload $class", DB_DATAOBJECT_ERROR_NOCLASS);
+            $dor = new DB_DataObject();
+            $dor->raiseError("could not autoload $class", DB_DATAOBJECT_ERROR_NOCLASS);
             $r = false;
             return $r;
         }
@@ -4808,7 +4853,8 @@ class DB_DataObject extends DB_DataObject_Overload
             $_DB_DATAOBJECT['CACHE'][$lclass] = array();
         }
         if (!$obj->get($k,$v)) {
-            DB_DataObject::raiseError("No Data return from get $k $v", DB_DATAOBJECT_ERROR_NODATA);
+            $dor = new DB_DataObject();
+            $dor->raiseError("No Data return from get $k $v", DB_DATAOBJECT_ERROR_NODATA);
             
             $r = false;
             return $r;