Clean old log records.

@param int $maxAgeInMonths

@return bool
764131
public function cleanLog($maxAgeInMonths)
    {
        $minimumDate = Carbon::now()->subMonths($maxAgeInMonths);
        Activity::where('created_at', '<=', $minimumDate)->delete();

        return true;
    }
616258
public static function rotateLogs( $dir, $filename, $maxSize=0, $maxFiles=0 )
    {
        $filepath = "$dir/$filename";
        if ( is_file( $filepath ) && filesize( $filepath ) > $maxSize )
        {
            if ( !rename( $filepath, $filepath . "." . strftime( '%Y%m%d_%H%M%S' ) ) )
            {
                eZPerfLoggerDebug::writeWarning( "Could not rotate log file $filepath", __METHOD__ );
            }
        }
        if ( $maxFiles )
        {
            $files = array();
            foreach( scandir( $dir ) as $afile )
            {
                if ( is_file( "$dir/$afile" ) && strpos( $afile, $filename ) === 0 )
                {
                    $ext = substr( strrchr( $afile, "." ), 1 );
                    $files[$ext] = $afile;
                }
            }
            if ( count( $files ) > $maxFiles )
            {
                ksort( $files );
                $oldest = "$dir/" . reset( $files );
                if ( !unlink( $oldest ) )
                {
                    eZPerfLoggerDebug::writeWarning( "Could not remove log file $oldest", __METHOD__ );
                }
            }
        }
    }
593332
public function gc($max)
    {
        if ($this->gcLifetime !== null) {
            $max = $this->gcLifetime;
        }
        if ($max == 0) {
            return true;
        }

        $stmt = $this->db->prepare("DELETE FROM " . $this->tableName . " WHERE session_lastaccesstime < DATE_SUB(NOW(), INTERVAL " . $max . " SECOND)");
        if ($stmt->execute()) {
            return true;
        }
        return false;
    }
309732
public function cleanRecentWorkspaces()
    {
        $this->log('Cleaning recent workspaces entries that are older than six months');

        /** @var WorkspaceRecentRepository $recentWorkspaceRepo */
        $recentWorkspaceRepo = $this->om->getRepository('ClarolineCoreBundle:Workspace\WorkspaceRecent');
        $recentWorkspaceRepo->removeAllEntriesBefore(new \DateTime('-6 months'));
    }
75728
public function clean() {
		if ( ! $this->enabled ) {
			return false;
		}

		$ttl      = $this->ttl;
		$max_size = $this->max_size;

		// unlink expired files
		if ( $ttl > 0 ) {
			try {
				$expire = new \DateTime();
			} catch ( \Exception $e ) {
				\WP_CLI::error( $e->getMessage() );
			}
			$expire->modify( '-' . $ttl . ' seconds' );

			$finder = $this->get_finder()->date( 'until ' . $expire->format( 'Y-m-d H:i:s' ) );
			foreach ( $finder as $file ) {
				unlink( $file->getRealPath() );
			}
		}

		// unlink older files if max cache size is exceeded
		if ( $max_size > 0 ) {
			$files = array_reverse( iterator_to_array( $this->get_finder()->sortByAccessedTime()->getIterator() ) );
			$total = 0;

			foreach ( $files as $file ) {
				if ( ( $total + $file->getSize() ) <= $max_size ) {
					$total += $file->getSize();
				} else {
					unlink( $file->getRealPath() );
				}
			}
		}

		return true;
	}
1091471
public function gc($maxlifetime)
    {
        $this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn, true) . ' + '
                    . $this->getAdapter()->quoteIdentifier($this->_lifetimeColumn, true) . ' < '
                    . $this->getAdapter()->quote(time()));

        return true;
    }
688129
public function cleanExpiredTokens($expiryTime)
    {
        $sql = "DELETE FROM {$this->tableName} WHERE {$this->expiresColumn} < ? ";

        $query = $this->connection->prepare($sql);
        $query->execute(array(date("Y-m-d H:i:s", $expiryTime)));
    }
804454
protected static function clear_old_records() {
        global $DB;

        $sql = "SELECT dpctx.*
                  FROM {tool_dataprivacy_ctxexpired} dpctx
             LEFT JOIN {context} ctx ON ctx.id = dpctx.contextid
                 WHERE ctx.id IS NULL";

        $orphaned = $DB->get_recordset_sql($sql);
        foreach ($orphaned as $orphan) {
            $expiredcontext = new expired_context(0, $orphan);
            $expiredcontext->delete();
        }

        // Delete any child of a user context.
        $parentpath = $DB->sql_concat('ctxuser.path', "'/%'");
        $params = [
            'contextuser' => CONTEXT_USER,
        ];

        $sql = "SELECT dpctx.*
                  FROM {tool_dataprivacy_ctxexpired} dpctx
                 WHERE dpctx.contextid IN (
                    SELECT ctx.id
                        FROM {context} ctxuser
                        JOIN {context} ctx ON ctx.path LIKE {$parentpath}
                       WHERE ctxuser.contextlevel = :contextuser
                    )";
        $userchildren = $DB->get_recordset_sql($sql, $params);
        foreach ($userchildren as $child) {
            $expiredcontext = new expired_context(0, $child);
            $expiredcontext->delete();
        }
    }
1145116
public function gc($maxlifetime)
    {
        foreach (glob($this->save_path."/*") as $file) {
            if (filemtime($file) + $maxlifetime < $this->createTimestamp() && file_exists($file)) {
                @unlink($file);
            }
        }

        return true;
    }
214328
public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context)
    {
        // If current version being asked to be deleted is not published, then don't delete keywords
        // if there is some other version which is published (as keyword table is not versioned)
        if ($versionInfo->status !== VersionInfo::STATUS_PUBLISHED &&
            $versionInfo->contentInfo->isPublished
        ) {
            return false;
        }

        foreach ($fieldIds as $fieldId) {
            $this->gateway->deleteFieldData($fieldId);
        }

        return true;
    }
486130
public function _gc($max) {
        $old = time() - $max;
        
        ORM::for_table($this->sessions_table)->raw_execute("DELETE * FROM " . $this->sessions_table . " WHERE access < :old", ['old' => $old]);
    }
924677
protected function cleanDirectory($directory, $maxAge = null, $keepMax = 5, array $blacklist = [], $quiet = true)
    {
        if (!is_dir($directory)) {
            return [0, 0];
        }
        $files = glob($directory . '/*');
        if (!$files) {
            return [0, 0];
        }
        // Sort files by modified time (descending).
        usort(
            $files,
            function ($a, $b) {
                return filemtime($a) < filemtime($b);
            }
        );
        $now = time();
        $numDeleted = 0;
        $numKept = 0;
        foreach ($files as $filename) {
            if (in_array($filename, $blacklist)) {
                $numKept++;
                continue;
            }
            if (($keepMax !== null && $numKept >= $keepMax)
                || ($maxAge !== null && $now - filemtime($filename) > $maxAge)) {
                if (!$quiet) {
                    $this->output->writeln("Deleting: " . basename($filename));
                }
                if ($this->fsHelper->remove($filename)) {
                    $numDeleted++;
                } elseif (!$quiet) {
                    $this->output->writeln("Failed to delete: <error>" . basename($filename) . "</error>");
                }
            } else {
                $numKept++;
            }
        }

        return [$numDeleted, $numKept];
    }
832812
public function purge($maxLifetime = 1440)
	{
		$past = time() - $maxLifetime;
		$query = $this->_db->getQuery(true)
			->delete($this->_db->quoteName($this->_tbl))
			->where($this->_db->quoteName('time') . ' < ' . (int) $past);
		$this->_db->setQuery($query);

		return $this->_db->execute();
	}
1008201
public function gc($maxlifetime)
    {
        if ($this->gcLimit === 0) {
            return true;
        }
        try {
            $query = $this->datastore->query()
                ->kind($this->kind)
                ->filter('t', '<', time() - $maxlifetime)
                ->order('t')
                ->keysOnly()
                ->limit($this->gcLimit);
            $result = $this->datastore->runQuery(
                $query,
                ['namespaceId' => $this->namespaceId]
            );
            $keys = [];
            /* @var Entity $e */
            foreach ($result as $e) {
                $keys[] = $e->key();
            }
            if (!empty($keys)) {
                $this->datastore->deleteBatch($keys);
            }
        } catch (Exception $e) {
            trigger_error(
                sprintf('Session gc failed: %s', $e->getMessage()),
                E_USER_WARNING
            );
            return false;
        }
        return true;
    }
332047
public function clean()
    {
        foreach ($this->cache as $key => $value) {
            list($expires, $value) = $value;
            if ($expires && ($expires < microtime(true))) {
                unset($this->cache[$key]);
            }
        }
        return true;
    }
258244
public function deleteFailedLoginAttempts($maxAge = null)
    {
        $sql = 'DELETE FROM FailedLoginAttempts';
        if ($maxAge) {
            $platform = $this->connection->getDatabasePlatform();
            $sql .= ' WHERE flaTimestamp <= ' . $platform->getDateSubSecondsExpression($platform->getNowExpression(), (int) $maxAge);
        }

        return (int) $this->connection->executeQuery($sql)->rowCount();
    }
131382
public function gc($maxlifetime): bool
    {
        DB::table('session')
            ->where('session_time', '<', Carbon::now()->subSeconds($maxlifetime))
            ->delete();

        return true;
    }