We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12983
    • 108 Posts
    Quick question: as in subject. But that’s just to be quick... I’d prefer a better solution: if you think you can give it, please read on.

    We use a snippet called "php" to execute scripts stored into filesystem: we use it in almost every node of our site, so that the content is not in database but on filesystem.

    In one of our pages, we have a problem with the "System Events" log feature of MODx: in fact, in this page we use fpdf and fpdi to generate pdf; but those projects make use of returning value of new by reference, which seems to be deprecated in PHP5. So MODx logs this into the System Events log:

    ’php - Snippet’,’Assigning the return value of new by reference is deprecated [...]’

    But, I’ve replaced with "[...]" the whole content of the page, which is huge and which is loaded many times a day, resulting in a quick grow of the database size just for logging it.

    Given that we do not want to modify fpdf’s and fpdi’s files, I’m here asking if you can suggest a way to avoid logging of the content, or at least to turn off the System Events log.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Not really recommended, preferable to fix the PHP code, but in manager/includes/document.parser.class.inc.php, around line 1287, you’ll find the function that inserts the events into the database. You could comment out the whole function definition body, or just the query and the query results check conditional at the end of the function.

      If I were going to do something like that, I would be more inclined to add some code to truncate the table if it gets beyond 50 or so entries; at least that way you would still have a way of seeing error conditions.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 12983
        • 108 Posts
        Could you tell me if this mod is fine?

            # Add an a alert message to the system event log
            function logEvent($evtid, $type, $msg, $source= 'Parser') {
            
            	$sql= "SELECT COUNT(*) FROM " . $this->getFullTableName("event_log");
            	$ds= @mysql_query($sql);
            	if ($ds > 50){
            		$sql= "TRUNCATE TABLE " . $this->getFullTableName("event_log");
            	} else {
            	// (the original stuff):
        			$msg= mysql_escape_string($msg);
        			$source= mysql_escape_string($source);
        			$evtid= intval($evtid);
        			if ($type < 1) {
        				$type= 1;
        			}
        			elseif ($type > 3) {
        				$type= 3; // Types: 1 = information, 2 = warning, 3 = error
        			}
        			$sql= "INSERT INTO " . $this->getFullTableName("event_log") . " (eventid,type,createdon,source,description,user) " .
        			"VALUES($evtid,$type," . time() . ",'$source','$msg','" . $this->getLoginUserID() . "')";
        			$ds= @mysql_query($sql);
        			if (!$ds) {
        				echo "Error while inserting event log into database.";
        				exit();
        			}
        			
        		}
            }
        


        (Original):

            # Add an a alert message to the system event log
            function logEvent($evtid, $type, $msg, $source= 'Parser') {
                $msg= mysql_escape_string($msg);
                $source= mysql_escape_string($source);
                $evtid= intval($evtid);
                if ($type < 1) {
                    $type= 1;
                }
                elseif ($type > 3) {
                    $type= 3; // Types: 1 = information, 2 = warning, 3 = error
                }
                $sql= "INSERT INTO " . $this->getFullTableName("event_log") . " (eventid,type,createdon,source,description,user) " .
                "VALUES($evtid,$type," . time() . ",'$source','$msg','" . $this->getLoginUserID() . "')";
                $ds= @mysql_query($sql);
                if (!$ds) {
                    echo "Error while inserting event log into database.";
                    exit();
                }
            }
        
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Like any SELECT query, it returns an array; you still need to get the first value out of the array before you get the count. I would use the MODx dbAPI call:
          $tablename = $modx->getFullTableName('event_log');
          $count = $modx->db->getValue($modx->db->select('COUNT(*)', $tablename));
          if($count > 50) { $modx->db->query('TRUNCATE TABLE' . $tablename); }


            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 12983
            • 108 Posts
            Damn, sure! Thank you very much, nice suggestion to use the db api.