Просмотр исходного кода

Merge branch 'master' of https://github.com/unaio/una

AntonLV 6 лет назад
Родитель
Сommit
9f10840f38

+ 50 - 8
inc/classes/BxDolDb.php

@@ -34,6 +34,9 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
     	BX_DB_ERR_ESCAPE => 'Escape string error'
     );
 
+    protected static $_bReadOnlyMode = true;
+    protected static $_bMultuServersMode = false;
+
 	protected $_bPdoPersistent;
 	protected $_iPdoFetchType;
 	protected $_iPdoErrorMode;
@@ -138,6 +141,40 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
     	return self::$_rLink;
     }
 
+    public function setReadOnlyMode($b)
+    {
+        if ($b == self::$_bReadOnlyMode)
+            return;
+        self::$_bReadOnlyMode = $b;
+        if (self::$_bMultuServersMode) {
+            $this->disconnect();
+            $this->connect();
+        }
+    }
+
+    protected function balancer()
+    {
+        // regular mode - one DB server
+        if (!is_array($this->_sHost))
+            return array($this->_sHost, $this->_sPort, $this->_sSocket, $this->_sUser, $this->_sPassword, $this->_sDbname);
+
+        $iServersNum = count($this->_sHost);
+        if ($iServersNum > 1)
+            self::$_bMultuServersMode = true;
+
+        // in read/write mode always use first server, which should be always master (also check for regular mode but with array with 1 item)        
+        if (!self::$_bReadOnlyMode || 1 == $iServersNum)
+            $i = 0;
+        // in case of 2 servers - always use second server, in read only mode
+        elseif (2 == $iServersNum)
+            $i = 1;
+        // when there are more that 2 servers, randomly select read only server
+        else
+            $i = rand(1, $iServersNum-1);
+            
+        return array($this->_sHost[$i], $this->_sPort[$i], $this->_sSocket[$i], $this->_sUser[$i], $this->_sPassword[$i], $this->_sDbname[$i]);
+    }
+
     /**
      * connect to database with appointed parameters
      */
@@ -146,13 +183,15 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
     	if(self::$_rLink)
     		return;
 
-    	try {
-	    	$sDsn = "mysql:host=" . $this->_sHost . ";";
-	   		$sDsn .= $this->_sPort ? "port=" . $this->_sPort . ";" : "";
-	   		$sDsn .= $this->_sSocket ? "unix_socket=" . $this->_sSocket . ";" : "";
-	    	$sDsn .= "dbname=" . $this->_sDbname . ";charset=" . $this->_sCharset;
+        list ($sHost, $sPort, $sSocket, $sUser, $sPassword, $sDBName) = $this->balancer();
+
+    	try {   
+	    	$sDsn = "mysql:host=" . $sHost . ";";
+	   		$sDsn .= $sPort ? "port=" . $sPort . ";" : "";
+	   		$sDsn .= $sSocket ? "unix_socket=" . $sSocket . ";" : "";
+	    	$sDsn .= "dbname=" . $sDBName . ";charset=" . $this->_sCharset;
 
-	        self::$_rLink = new PDO($sDsn, $this->_sUser, $this->_sPassword, array(
+	        self::$_rLink = new PDO($sDsn, $sUser, $sPassword, array(
 				PDO::ATTR_ERRMODE => $this->_iPdoErrorMode,
 				PDO::ATTR_DEFAULT_FETCH_MODE => $this->_iPdoFetchType,
 				PDO::ATTR_PERSISTENT => $this->_bPdoPersistent
@@ -973,6 +1012,9 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
     	if(!self::$_rLink)
     		return false;
 
+        if (self::$_bMultuServersMode && (0 != strncasecmp(ltrim($sQuery, " \t\n\r(\0\x0B"), 'SELECT', 6)))
+            $this->setReadOnlyMode(false);
+
         $aArgs = func_get_args();
         $sQuery = array_shift($aArgs);
 
@@ -1217,9 +1259,9 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
         
 		if(!empty($aError['trace'])) {
             $sBackTrace = print_r($aError['trace'], true);
-            if (defined ('BX_DATABASE_USER'))
+            if (defined ('BX_DATABASE_USER') && !is_array(BX_DATABASE_USER))
                 $sBackTrace = str_replace('[_sUser:protected] => ' . BX_DATABASE_USER, '[_sUser:protected] => *****', $sBackTrace);
-            if (defined ('BX_DATABASE_PASS'))
+            if (defined ('BX_DATABASE_PASS') && !is_array(BX_DATABASE_PASS))
                 $sBackTrace = str_replace('[_sPassword:protected] => ' . BX_DATABASE_PASS, '[_sPassword:protected] => *****', $sBackTrace);
 
 			$sOutput .= '<div><b>Debug backtrace:</b></div><div style="overflow:scroll;height:300px;border:1px solid gray;"><pre>' . htmlspecialchars_adv($sBackTrace) . '</pre></div>';

+ 4 - 0
inc/classes/BxDolProfile.php

@@ -526,6 +526,10 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
      */
     public function suspend($iAction, $iProfileId = 0, $bSendEmailNotification = true)
     {
+        //moderators shouldn't be able to suspend other moderators and admins
+        if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), bx_get_logged_profile_id()) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iProfileId))
+            return false;
+        
         return $this->changeStatus(BX_PROFILE_STATUS_SUSPENDED, 'suspend', $iAction, $iProfileId, $bSendEmailNotification);
     }
 

+ 5 - 0
inc/classes/BxDolReport.php

@@ -189,6 +189,11 @@ class BxDolReport extends BxDolObject
         return echoJson($this->_getReport());
     }
 
+    public function actionClearReport()
+    {
+       $this->_oQuery->clearReports($this->getId());
+    }
+    
     public function actionGetReportedBy()
     {
         if (!$this->isEnabled())

+ 9 - 0
inc/classes/BxDolReportQuery.php

@@ -70,6 +70,15 @@ class BxDolReportQuery extends BxDolObjectQuery
 
         return (int)$this->query($sQuery) != 0;
     }
+    
+    public function clearReports($iObjectId)
+    {
+        $sQuery = $this->prepare("DELETE FROM `{$this->_sTable}` WHERE `object_id` = ?", $iObjectId);
+        $this->query($sQuery);
+        
+        $sQuery = $this->prepare("DELETE FROM `{$this->_sTableTrack}` WHERE `object_id` = ?", $iObjectId);
+        $this->query($sQuery);
+    }
 }
 
 /** @} */

+ 3 - 1
inc/classes/BxDolSessionQuery.php

@@ -40,7 +40,9 @@ class BxDolSessionQuery extends BxDolDb
     	$sSet = !empty($aSet) ? $this->arrayToSQL($aSet) . ", " : "";
     	$sSet .= "`date`=UNIX_TIMESTAMP()";
 
-        return (int)$this->query("UPDATE `" . $this->sTable . "` SET " . $sSet . " WHERE `id`=:id", array('id' => $sId)) > 0;
+        $iRet = (int)$this->query("UPDATE `" . $this->sTable . "` SET " . $sSet . " WHERE `id`=:id", array('id' => $sId)) > 0;
+        $this->setReadOnlyMode(true);
+        return $iRet;
     }
     function delete($sId)
     {

+ 3 - 1
inc/classes/BxDolTranscoderQuery.php

@@ -94,7 +94,9 @@ class BxDolTranscoderQuery extends BxDolDb
     {
         $iTime = time();
         $sQuery = $this->prepare("UPDATE {$this->_sTableFiles} SET `atime` = ? WHERE `transcoder_object` = ? AND `handler` = ? LIMIT 1", $iTime, $this->_aObject['object'], (string)$mixedHandler);
-        return $this->res($sQuery);
+        $mixedRes = $this->res($sQuery);
+        $this->setReadOnlyMode(true);
+        return $mixedRes;
     }
 
     public function deleteFileTraces($iFileId)

+ 1 - 1
inc/profiles.inc.php

@@ -157,7 +157,7 @@ function check_logged()
     $bLogged = false;
     foreach ($aAccTypes as $iRole => $sValue) {
         if ($GLOBALS['logged'][$sValue] = ($sID && !bx_check_login($sID, $sPassword, $iRole))) {
-            BxDolSession::getInstance()->start();
+            BxDolSession::getInstance();
             $bLogged = true;
             break;
         }

+ 24 - 0
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -65,6 +65,30 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
         echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
     }
     
+    public function performActionClearReports($aParams = array())
+    {
+    	$CNF = &$this->_oModule->_oConfig->CNF;
+
+        $iAffected = 0;
+        $aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) {
+            echoJson(array());
+            exit;
+        }
+
+        $aIdsAffected = array ();
+        foreach($aIds as $iId) {
+            if (isset($CNF['OBJECT_REPORTS'])){
+                $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iId);
+                $oReport->actionClearReport();
+                $aIdsAffected[] = $iId;
+                $iAffected++;
+            }
+        }
+
+        echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_clear_reports'])));
+    }
+
     protected function _getActionAuditContent($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if (!getParam('sys_audit_enable') || getParam('sys_audit_acl_levels') == '')

+ 1 - 0
modules/boonex/posts/install/langs/en.xml

@@ -258,6 +258,7 @@
     <string name="_bx_posts_grid_action_title_adm_add"><![CDATA[Add]]></string>
     <string name="_bx_posts_grid_action_title_adm_edit"><![CDATA[Edit]]></string>
     <string name="_bx_posts_grid_action_title_adm_delete"><![CDATA[Delete]]></string>
+    <string name="_bx_posts_grid_action_title_adm_clear_reports"><![CDATA[Сlear reports]]></string>
     <string name="_bx_posts_grid_action_title_adm_more_actions"><![CDATA[More Actions]]></string>
     <string name="_bx_posts_grid_action_err_delete"><![CDATA[Cannot delete the selected post(s).]]></string>
     <string name="_bx_posts_grid_txt_account_manager"><![CDATA[Redirect to manage account.]]></string>

+ 2 - 0
modules/boonex/posts/install/sql/enable.sql

@@ -473,10 +473,12 @@ INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon_only`, `confirm`, `order`) VALUES
 ('bx_posts_administration', 'bulk', 'delete', '_bx_posts_grid_action_title_adm_delete', '', 0, 1, 1),
+('bx_posts_administration', 'bulk', 'clear_reports', '_bx_posts_grid_action_title_adm_clear_reports', '', 0, 1, 1),
 ('bx_posts_administration', 'single', 'edit', '_bx_posts_grid_action_title_adm_edit', 'pencil-alt', 1, 0, 1),
 ('bx_posts_administration', 'single', 'delete', '_bx_posts_grid_action_title_adm_delete', 'remove', 1, 1, 2),
 ('bx_posts_administration', 'single', 'settings', '_bx_posts_grid_action_title_adm_more_actions', 'cog', 1, 0, 3),
 ('bx_posts_administration', 'single', 'audit_content', '_bx_posts_grid_action_title_adm_audit_content', 'search', 1, 0, 4),
+('bx_posts_administration', 'single', 'clear_reports', '_bx_posts_grid_action_title_adm_clear_reports', 'search', 1, 0, 5),
 ('bx_posts_common', 'bulk', 'delete', '_bx_posts_grid_action_title_adm_delete', '', 0, 1, 1),
 ('bx_posts_common', 'single', 'edit', '_bx_posts_grid_action_title_adm_edit', 'pencil-alt', 1, 0, 1),
 ('bx_posts_common', 'single', 'delete', '_bx_posts_grid_action_title_adm_delete', 'remove', 1, 1, 2),

+ 3 - 1
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -459,7 +459,9 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         if(empty($aParamsSet))
             return false;
 
-        return (int)$this->query("REPLACE INTO `{$this->_sTableCache}` SET " . $this->arrayToSQL($aParamsSet)) > 0;
+        $iRet = (int)$this->query("REPLACE INTO `{$this->_sTableCache}` SET " . $this->arrayToSQL($aParamsSet)) > 0;
+        $this->setReadOnlyMode(true);
+        return $iRet;
     }
 
     public function deleteCache($aParamsWhere)

+ 3 - 0
template/css/default.less

@@ -137,6 +137,9 @@
 .bx-def-margin-sec-top {
     .margin-top(@bx-margin-sec);
 }
+.bx-def-margin-sec-top-neg {
+    .margin-top(-@bx-margin-sec);
+}
 .bx-def-margin-sec-top-auto {
     .margin-top(@bx-margin-sec);
     &:first-child {

+ 2 - 0
template/scripts/BxBasePage.php

@@ -415,6 +415,8 @@ class BxBasePage extends BxDolPage
 
             $sTitle = $this->getBlockTitle($aBlock);
 
+            $this->_oQuery->setReadOnlyMode(true);
+
             if(is_array($mixedContent) && !empty($mixedContent['content'])) {
                 $aParams = array(
                     isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle,

+ 2 - 0
template/scripts/BxBaseServices.php

@@ -372,6 +372,8 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             $sCode = $oSearch->response();
             if (!$sCode)
                 $sCode = $oSearch->getEmptyResult();
+            else
+                $sCode = '<div class="bx-def-margin-sec-top-neg">' . $sCode . '</div>';
         }
 
         return $sCode;