Ejemplo n.º 1
0
 /**
  * Singleton should be used to save memory.
  * It keeps 1 global object that is used by BS for each type of DB object
  *
  * @param Fu_DB_Base based object
  * @return Fu_DB_Association object instance
  */
 public function singleton($class)
 {
     $instance = Fu_Reg::get("association_{$class}");
     if (is_null($instance)) {
         $instance = Fu_Reg::set("association_{$class}", new Fu_DB_Association($dbo));
     } else {
         // as we are restoring this object from the global register, we freeze it
         $instance->frozen = true;
     }
     return $instance;
 }
Ejemplo n.º 2
0
<?php

/**
 * This class database debugging
 */
Fu_Reg::set('fu_db_debug', new Fu_DB_Debug());
class Fu_DB_Debug
{
    private $info = array(), $debug = false;
    /**
     * Handles certain housekeeping tasks to keep the flash messages in order.
     */
    function __construct()
    {
        if (defined('FU_DB_DEBUG') && FU_DB_DEBUG === true) {
            $this->debug = true;
        }
    }
    public function debug($s = null, $p = array())
    {
        if (!(isset($this) && get_class($this) == __CLASS__)) {
            $instance = Fu_Reg::get("fu_db_debug");
            return $instance->debug($s, $p);
        }
        if ($this->debug) {
            if ($s) {
                $this->info[] = array('sql' => $s, 'params' => $p);
            } else {
                return $this->info;
            }
        }
Ejemplo n.º 3
0
Archivo: DB.php Proyecto: kelvinj/Giiki
 public static function rollback()
 {
     $depth = (int) Fu_Reg::get('Fu_DB_Transaction_Depth');
     Fu_Reg::set('Fu_DB_Transaction_Depth', $depth - 1);
     if ($depth > 1) {
         return;
     } else {
         // at the root transaction
         $dbh = Fu_Reg::get('dbh');
         $dbh->rollback();
     }
 }
Ejemplo n.º 4
0
<?php

/**
 * This class handles feedback given to the user. In the form of:
 *
 *  - errors (multiple)
 *  - flash messages
 *
 *  Errors are added to stacks. By default there is one stack (default)
 *  which is used for general errors. Errors can be added to another stack,
 *  e.g. 'debug', which can be conditionally called up fro the view. It is also
 *  possible to only allow a certain stack in a certain environment.
 *
 *  Flash messages persist over 1 page request, but are then destroyed.
 */
Fu_Reg::set('fu_feedback', new Fu_Feedback());
class Fu_Feedback
{
    private $errors = array(), $flashes, $flash_key = '__fu_feedback_flash_messages';
    /**
     * Handles certain housekeeping tasks to keep the flash messages in order.
     */
    function __construct()
    {
        session_start();
        $key = $this->flash_key;
        if ($_SESSION[$key]) {
            $this->flashes = $_SESSION[$key];
            $_SESSION[$key] = array();
        }
    }
Ejemplo n.º 5
0
 function _check_installation()
 {
     $errors = array();
     do {
         if (!is_writable($this->data_dir)) {
             $errors[] = "Data directory not writeable ({$this->data_dir})";
             break;
         }
         if (!is_dir($this->data_dir . '/.git')) {
             // no git install, try to fix
             if (!file_exists($this->data_dir . '/.gitignore')) {
                 // pop a git ignore file in to ignore the sql db
                 file_put_contents($this->data_dir . '/.gitignore', ".DS_Store\n*.db\n");
             }
             if ($this->git->init()) {
                 exec('chmod -R 0777 ' . $this->data_dir);
                 $this->git->add_all_commit('adding existing pages');
             } else {
                 $errors[] = "Could not initialize git repository ({$this->data_dir}/.git)";
             }
         }
         if (!file_exists($this->data_dir . '/.sqlite.db')) {
             // no sql db
             if (!copy(ROOT . '/giiki/virgin.db', $this->data_dir . '/.sqlite.db')) {
                 $errors[] = "Could not copy SQLite database ({$this->data_dir}/.sqlite.db)";
             } else {
                 Fu_Reg::set('dbh', new PDO($this->dsn));
                 $dbo = new DB_User();
                 $admin_user = $dbo->find(1);
                 $admin_user->rand_token();
                 $admin_user->save();
             }
         }
     } while (0);
     if ($errors) {
         echo implode('<br />', $errors);
         exit;
     }
 }