disconnect() public static method

Disconnects from database (doesn't destroy Connection object).
public static disconnect ( ) : void
return void
Exemplo n.º 1
0
 /**
  * Helpers to test SQL connection and send a test email.
  * @param $action
  * @param $httpVars
  * @param $fileVars
  * @throws Exception
  */
 public function testConnexions($action, $httpVars, $fileVars)
 {
     $data = array();
     AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "DRIVER_OPTION_");
     if ($action == "boot_test_sql_connexion") {
         $p = AJXP_Utils::cleanDibiDriverParameters($data["db_type"]);
         if ($p["driver"] == "sqlite3") {
             $dbFile = AJXP_VarsFilter::filter($p["database"]);
             if (!file_exists(dirname($dbFile))) {
                 mkdir(dirname($dbFile), 0755, true);
             }
         }
         // Should throw an exception if there was a problem.
         dibi::connect($p);
         dibi::disconnect();
         echo 'SUCCESS:Connexion established!';
     } else {
         if ($action == "boot_test_mailer") {
             $mailerPlug = AJXP_PluginsService::findPluginById("mailer.phpmailer-lite");
             $mailerPlug->loadConfigs(array("MAILER" => $data["MAILER_ENABLE"]["MAILER_SYSTEM"]));
             $mailerPlug->sendMail(array("adress" => $data["MAILER_ENABLE"]["MAILER_ADMIN"]), "Pydio Test Mail", "Body of the test", array("adress" => $data["MAILER_ENABLE"]["MAILER_ADMIN"]));
             echo 'SUCCESS:Mail sent to the admin adress, please check it is in your inbox!';
         }
     }
 }
 public function upgradeDB()
 {
     $confDriver = ConfService::getConfStorageImpl();
     $authDriver = ConfService::getAuthDriverImpl();
     $logger = AJXP_Logger::getInstance();
     if (is_a($confDriver, "sqlConfDriver")) {
         $conf = AJXP_Utils::cleanDibiDriverParameters($confDriver->getOption("SQL_DRIVER"));
         if (!is_array($conf) || !isset($conf["driver"])) {
             return "Nothing to do";
         }
         switch ($conf["driver"]) {
             case "sqlite":
             case "sqlite3":
                 $ext = ".sqlite";
                 break;
             case "postgre":
                 $ext = ".pgsql";
                 break;
             case "mysql":
                 $ext = is_file($this->workingFolder . "/" . $this->dbUpgrade . ".mysql") ? ".mysql" : ".sql";
                 break;
             default:
                 return "ERROR!, DB driver " . $conf["driver"] . " not supported yet in __FUNCTION__";
         }
         $file = $this->dbUpgrade . $ext;
         if (!is_file($this->workingFolder . "/" . $file)) {
             return "Nothing to do.";
         }
         $sqlInstructions = file_get_contents($this->workingFolder . "/" . $file);
         $parts = array_map("trim", explode("/* SEPARATOR */", $sqlInstructions));
         $results = array();
         $errors = array();
         dibi::connect($conf);
         dibi::begin();
         foreach ($parts as $sqlPart) {
             if (empty($sqlPart)) {
                 continue;
             }
             try {
                 dibi::nativeQuery($sqlPart);
                 $results[] = $sqlPart;
             } catch (DibiException $e) {
                 $errors[] = $sqlPart . " (" . $e->getMessage() . ")";
             }
         }
         dibi::commit();
         dibi::disconnect();
         if (!count($errors)) {
             return "Database successfully upgraded";
         } else {
             return "Database upgrade failed. <br>The following statements were executed : <br>" . implode("<br>", $results) . ",<br><br> The following statements failed : <br>" . implode("<br>", $errors) . "<br><br> You should manually upgrade your DB.";
         }
     }
 }
Exemplo n.º 3
0
 public function installSQLTables($param)
 {
     $p = AJXP_Utils::cleanDibiDriverParameters($param["SQL_DRIVER"]);
     $res = AJXP_Utils::runCreateTablesQuery($p, $this->getBaseDir() . "/create.sql");
     // SET DB VERSION
     if (defined('AJXP_VERSION_DB') && AJXP_VERSION_DB != "##DB_VERSION##") {
         dibi::connect($p);
         dibi::query("UPDATE [ajxp_version] SET [db_build]=%i", intval(AJXP_VERSION_DB));
         dibi::disconnect();
     }
     return $res;
 }
Exemplo n.º 4
0
 public static function runCreateTablesQuery($p, $file)
 {
     switch ($p["driver"]) {
         case "sqlite":
         case "sqlite3":
             if (!file_exists(dirname($p["database"]))) {
                 @mkdir(dirname($p["database"]), 0755, true);
             }
             $ext = ".sqlite";
             break;
         case "mysql":
             $ext = ".mysql";
             break;
         case "postgre":
             $ext = ".pgsql";
             break;
         default:
             return "ERROR!, DB driver " . $p["driver"] . " not supported yet in __FUNCTION__";
     }
     $result = array();
     $file = dirname($file) . "/" . str_replace(".sql", $ext, basename($file));
     $sql = file_get_contents($file);
     $separators = explode("/** SEPARATOR **/", $sql);
     $allParts = array();
     foreach ($separators as $sep) {
         $explode = explode("\n", trim($sep));
         $firstLine = array_shift($explode);
         if ($firstLine == "/** BLOCK **/") {
             $allParts[] = $sep;
         } else {
             $parts = explode(";", $sep);
             $remove = array();
             for ($i = 0; $i < count($parts); $i++) {
                 $part = $parts[$i];
                 if (strpos($part, "BEGIN") && isset($parts[$i + 1])) {
                     $parts[$i] .= ';' . $parts[$i + 1];
                     $remove[] = $i + 1;
                 }
             }
             foreach ($remove as $rk) {
                 unset($parts[$rk]);
             }
             $allParts = array_merge($allParts, $parts);
         }
     }
     dibi::connect($p);
     dibi::begin();
     foreach ($allParts as $createPart) {
         $sqlPart = trim($createPart);
         if (empty($sqlPart)) {
             continue;
         }
         try {
             dibi::nativeQuery($sqlPart);
             $resKey = str_replace("\n", "", substr($sqlPart, 0, 50)) . "...";
             $result[] = "OK: {$resKey} executed successfully";
         } catch (DibiException $e) {
             $result[] = "ERROR! {$sqlPart} failed";
         }
     }
     dibi::commit();
     dibi::disconnect();
     $message = implode("\n", $result);
     if (strpos($message, "ERROR!")) {
         return $message;
     } else {
         return "SUCCESS:" . $message;
     }
 }
Exemplo n.º 5
0
function renderXml($ak, $xml)
{
    if ($xml == '') {
        require PHPINC_DIR . '/templates/404_record.php';
    } else {
        dibi::disconnect();
        if ($ak == '_sxml') {
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header('Content-Disposition: attachment; filename="metadata.xml"');
        }
        header("Content-type: application/xml");
        echo $xml;
        exit;
    }
}
 public function testSQLConnexion($httpVars)
 {
     $p = AJXP_Utils::cleanDibiDriverParameters($httpVars["SQL_CUSTOM_DRIVER"]);
     if ($p["driver"] == "sqlite3") {
         $dbFile = AJXP_VarsFilter::filter($p["database"]);
         if (!file_exists(dirname($dbFile))) {
             mkdir(dirname($dbFile), 0755, true);
         }
     }
     // Should throw an exception if there was a problem.
     dibi::connect($p);
     $cTableName = $httpVars["SQL_CUSTOM_TABLE"];
     $cUserField = $httpVars["SQL_CUSTOM_TABLE_USER_FIELD"];
     $cUserValue = $httpVars["SQL_CUSTOM_TABLE_TEST_USER"];
     $res = dibi::query("SELECT COUNT(*) FROM [" . $cTableName . "] WHERE [" . $cUserField . "]=%s", $cUserValue);
     $found = intval($res->fetchSingle()) > 0;
     if (!$found) {
         throw new Exception("Could connect to the DB but could not find user " . $cUserValue);
     }
     dibi::disconnect();
     echo "SUCCESS:Connexion established and user {$cUserValue} found in DB";
 }
Exemplo n.º 7
0
        echo "Upgrading MYSQL database ...";
        $parts = array_map("trim", explode("/* SEPARATOR */", $dbInst));
        $results = array();
        $errors = array();
        require_once AJXP_BIN_FOLDER . "/dibi.compact.php";
        dibi::connect($test);
        dibi::begin();
        foreach ($parts as $sqlPart) {
            if (empty($sqlPart)) {
                continue;
            }
            try {
                dibi::nativeQuery($sqlPart);
                echo "<div class='upgrade_result success'>{$sqlPart} ... OK</div>";
            } catch (DibiException $e) {
                $errors[] = $e->getMessage();
                echo "<div class='upgrade_result success'>{$sqlPart} ... FAILED (" . $e->getMessage() . ")</div>";
            }
        }
        dibi::commit();
        dibi::disconnect();
    } else {
        if (is_array($test) && $test["driver"] != "mysql") {
            echo "Cannot auto-upgrade Sqlite or PostgreSql DB automatically, please review the update instructions.";
        } else {
            echo "Nothing to do for the DB";
        }
    }
} else {
    echo "Nothing to do for the DB";
}
function udfRecognitionTest2($xmlfile)
{
    $dbusername = "******";
    $dbpassword = "******";
    $dbserver = "localhost";
    $dbid = "face_recognition";
    dibi::connect(array('driver' => 'mysql', 'host' => $dbserver, 'username' => $dbusername, 'password' => $dbpassword, 'database' => $dbid, 'charset' => 'utf8'));
    //Set up the parser object
    $parser = new DOMDocument();
    $parser->loadXML($xmlfile);
    $maxDistance = 100;
    $minPersonId = -1;
    $vectors = $parser->getElementsByTagName("Vector");
    foreach ($vectors as $vector) {
        $vectorData = $vector->nodeValue;
        //vnoreny foreach - pre vsetky vektory v databaze a pre vsetky vectory v xml testuj vzdialenost
        $result = dibi::query('call face_recognition.FindPersonUDF(%s)', $vectorData);
        $persons_id = array();
        $podobnost = array();
        foreach ($result as $n => $row) {
            array_push($persons_id, $row['id_person_res']);
            array_push($podobnost, $row['min_dist']);
        }
        if (empty($podobnost)) {
            return "Chyba";
        }
        //porovnanie s minimalnou vzdialenostou a osetrenie, ci nenastala chyba
        if ($podobnost[0] > $maxDistance || $podobnost[0] == -1) {
            return "Nenasla sa zhoda!";
        }
        $result->free();
        unset($result);
        dibi::disconnect();
        dibi::connect(array('driver' => 'mysql', 'host' => $dbserver, 'username' => $dbusername, 'password' => $dbpassword, 'database' => $dbid, 'charset' => 'utf8'));
        //selectne meno osoby , ktora vlastni vector s minimalnou vzdialenostou
        $result = dibi::query('SELECT name FROM face_recognition.person WHERE idperson=%i', $persons_id[0]);
        $menoRozpoznanejOsoby = array();
        foreach ($result as $n => $row) {
            array_push($menoRozpoznanejOsoby, $row['name']);
        }
        return "OK! value={$podobnost['0']} idPerson={$persons_id['0']} meno={$menoRozpoznanejOsoby['0']}";
    }
    return "Chyba parsovania";
}
Exemplo n.º 9
0
function adminProfils($profilAction)
{
    require PHPINC_DIR . '/admin/profils/app/Profil.php';
    $rs = array();
    $NTree = new Tree();
    $mds = isset($_GET['mds']) ? htmlspecialchars($_GET['mds']) : 0;
    $mdid = isset($_GET['mdid']) ? htmlspecialchars($_GET['mdid']) : 0;
    $profil = isset($_GET['p']) ? htmlspecialchars($_GET['p']) : '';
    switch ($profilAction) {
        //==========================================================================
        case 'listp':
            // profil save
            //==========================================================================
            $pr = getMdProfils(MICKA_LANG, $mds);
            $template = new FileTemplate();
            $template->setFile(PHPINC_DIR . '/admin/profils/templates/list.latte');
            /* pro PHP 5.3, v PHP 5.2 nefunguje
            			$template->onPrepareFilters[] = function($template) {
            					$template->registerFilter(new LatteFilter());
            			};
                         */
            // pro PHP 5.2
            $template->registerHelperLoader('TemplateHelpers::loader');
            $template->registerFilter(new LatteFilter());
            $template->basePath = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
            $template->themePath = $template->basePath . '/themes/' . MICKA_THEME;
            $template->label = getLabelAllAP();
            $template->MICKA_USER = MICKA_USER;
            $template->tree_view = $NTree->getListProfil($profil);
            $template->profil_names = $pr[$profil];
            dibi::disconnect();
            //Debugger::dump($template->tree_view); exit;
            $template->render();
            exit;
            break;
            //==========================================================================
        //==========================================================================
        case 'newp':
            //==========================================================================
            $rs['mds'] = $mds;
            $rs['select_true'] = array(0 => 'No', 1 => 'Yes');
            $rs['profil_names'] = $NTree->getProfilNames($mds, $profil);
            $rs['lite_templates'] = $NTree->getLiteTemplates();
            $rs['copy_profils'] = $NTree->getProfils($mds, TRUE);
            break;
            //==============================================================================
        //==============================================================================
        case 'delpro':
            // smazani podřízené větve z profilu
            //==============================================================================
            $mdid_ch = isset($_GET['mdid_ch']) ? htmlspecialchars($_GET['mdid_ch']) : 0;
            $mdid_ch = $mdid_ch == 0 ? -1 : $mdid_ch;
            $profil = $profil == '' ? -1 : $profil;
            $NTree->deleteMdidFromProfil($mds, $mdid_ch, $profil);
            //==============================================================================
        //==============================================================================
        case 'addpro':
            // přidání větve do profilu
            //==============================================================================
            if ($profilAction == 'addpro') {
                $mdid_ch = isset($_GET['mdid_ch']) ? htmlspecialchars($_GET['mdid_ch']) : 0;
                $mdid_ch = $mdid_ch == 0 ? -1 : $mdid_ch;
                $profil = $profil == '' ? -1 : $profil;
                $NTree->checkProfilMD($profil, $mdid_ch);
            }
            //==========================================================================
        //==========================================================================
        case 'setp':
            //==========================================================================
            if ($profilAction == 'setp') {
                $NTree->setProfilNames($_POST);
            }
            //==========================================================================
        //==========================================================================
        case 'delp':
            //==========================================================================
            if ($profilAction == 'delp') {
                $NTree->delProfilNames($profil);
            }
            //==========================================================================
        //==========================================================================
        case 'change_standard':
            // change standard
            //==========================================================================
            if (isset($_POST['mds'])) {
                $mds = $_POST['mds'] == 0 || $_POST['mds'] == 10 || $_POST['mds'] || $_POST['mds'] == 1 || $_POST['mds'] == 2 ? $_POST['mds'] : 0;
                $redirectUrl = substr(htmlspecialchars($_SERVER['PHP_SELF']), 0, strrpos($_SERVER['PHP_SELF'], '/')) . '?ak=admin&adm_ak=profils&mds=' . $mds;
                require PHPPRG_DIR . '/redirect.php';
            }
            //==========================================================================
        //==========================================================================
        default:
            //==========================================================================
            $labelnode = $NTree->getLabelNode($mdid, $mds);
            $listnodes = $NTree->getListNodes($mdid, $mds);
            $profily = $NTree->getProfilPath($mds);
            if ($mds == 0 || $mds == 10) {
                $del_profil = $NTree->deleteMDprofilPath($profily);
                $del_mdid = $NTree->deleteMDidPath($listnodes);
                if ($del_profil != '' && $del_mdid != '') {
                    $sel_profily = $NTree->checkProfilSelect($del_mdid, $del_profil);
                }
            }
            $rs['mds'] = $mds;
            $rs['mdid'] = $mdid;
            $rs['form']['standard'] = $NTree->getMdStandardAll();
            $rs['form']['profil_names'] = $NTree->getProfils($mds);
            $rs['form']['label_node'] = $labelnode;
            $rs['form']['list_nodes'] = $listnodes;
            $rs['form']['list_profil'] = $profily;
            $rs['form']['SelectProfil'] = $sel_profily;
    }
    //Debugger::dump($rs); exit;
    //Debugger::dump($rs['form']); exit;
    return $rs;
}