/** * Deletes all data from a database table * * @version 1.0 * @since 1.0 * @return bool | Exception on failure. True on success. */ public function truncate() { if ($this->debug_on) { extract($this->debug_handler->event(array('pid' => $this->process_id, 'text' => "method_start", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'parent' => $this, 'vars' => compact(array_keys(get_defined_vars()))))); } $db = new FOX_db(array('pid' => $this->process_id)); try { $db->runTruncateTable($this->_struct()); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 1, 'text' => "Failed to truncate table", 'data' => array('struct' => $this->_struct()), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } if ($this->debug_on) { extract($this->debug_handler->event(array('pid' => $this->process_id, 'text' => "method_end", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'parent' => $this, 'vars' => compact(array_keys(get_defined_vars()))))); } return true; }
/** * Deletes the entire user data store, and flushes the cache. Generally * used for testing and debug. * * @version 1.0 * @since 1.0 * * @return bool | False on failure. True on success. */ public function dropAll(&$error = null) { global $rad; $db = new FOX_db(); try { $query_ok = $db->runTruncateTable(self::$struct); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 1, 'text' => "Error while clearing the database", 'data' => null, 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } // Since this operation affects *all* user_id's, we have to flush the cache try { $cache_ok = self::flushCache(); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Cache flush exception", 'data' => null, 'file' => __FILE__, 'line' => __LINE__, 'method' => __METHOD__, 'child' => $child)); } if ($cache_ok) { return true; } else { return false; } }
/** * Deletes the entire datastore * * @version 1.0 * @since 1.0 * @return int | Exception on failure. Number of db rows changed on success. */ public function dropAll() { $db = new FOX_db(); $struct = $this->_struct(); // Lock the cache // =========================================================== try { self::lockCache(); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 1, 'text' => "Error locking cache", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } // Clear the database // =========================================================== try { $db->runTruncateTable($struct); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Error truncating database table", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } // Flush the cache // =========================================================== try { self::flushCache(); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 3, 'text' => "Error flushing cache", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } return true; }
/** * Deletes the entire module data store, and flushes the cache. Generally * used for testing and debug. * * @version 1.0 * @since 1.0 * @return bool | Exception on failure. True on success. */ public function dropAll() { $db = new FOX_db(); $struct = $this->_struct(); try { $db->runTruncateTable($struct); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 1, 'text' => "Error while clearing the database", 'data' => null, 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } // Since this operation affects *all* module_id's, we have to flush // the entire cache namespace try { self::flushCache(); } catch (FOX_exception $child) { throw new FOX_exception(array('numeric' => 2, 'text' => "Cache flush error", 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => $child)); } }