Home > Mobile >  can i use || and && together?
can i use || and && together?

Time:10-30

im trying to open a log file and see if a text does not exist, if it doesnt exist then continue, but at the same time i want to check its the log file has not been sent per mail already.

        public function start() {

    $pattern = $this->config["twp_pattern"] ?? '*.log';
    $pathLog = (isset($this->config["twp_path"])) ? trim($this->config["twp_path"], '/') : 'var/log';
    $lastRun = (isset($this->config['twp_last_run'])) ? str_replace('T', ' ', $this->config['twp_last_run']) : false;

    $path = getcwd() . '/' . $pathLog . '/' . $pattern;

    $this->now = new \DateTime();


    foreach (glob($path) as $log) {
        $open = fopen($log, 'r') or die ('File opening failed');
        $content = fread($open,filesize($log));
        var_dump($content);
        fclose($log);
        if (!$lastRun || filectime($log) < strtotime($lastRun) && $this->checkIfAlreadyExists($content) === false) {
            continue;
        }
        $logs[] = $log;
    }


    if (!empty($logs)) {
        $success =$this->sendMail($logs);
    }

    if($success === false){
        return false;
    }
    $this->setLastRun();

    return true;

}

public function checkIfAlreadyExists($content){
    if (!preg_match_all('/already exists/', $content)) {
        echo "is not there";
        return false;
    }else{
        echo "is there";
        return true;
    }
}

my problem is even tho email has been sent, it will send it again when i run function start() if i remove the && $this->checkIfAlreadyExists($content) === false, it will not longer send logs per mail that has already been sent. can anyone spot my mistake ? Thanks

CodePudding user response:

Fixed by changing my if statement

if ((!$lastRun || filectime($log) < strtotime($lastRun)) || ($this->checkIfAlreadyExists($content))) {
                continue;
            }

Thanks for your time and the help ! <3

  • Related