Airship\Cabin\Bridge\Blueprint\Files::getUniqueFileName PHP Method

getUniqueFileName() protected method

Get a string that doesn't get exist in the DB
protected getUniqueFileName ( string $name, string $ext, integer | null $directoryId = null, string $cabin = '' ) : string
$name string
$ext string
$directoryId integer | null
$cabin string
return string
    protected function getUniqueFileName(string $name, string $ext, $directoryId = null, string $cabin = '') : string
    {
        if (empty($directoryId)) {
            $queryString = 'SELECT
                count(*)
            FROM
                airship_files
            WHERE
                    filename = ? 
                AND directory IS NULL
                AND cabin = ?';
            $subParam = $cabin;
        } else {
            $queryString = 'SELECT
                count(*)
            FROM
                airship_files
            WHERE
                    filename = ? 
                AND directory = ?';
            $subParam = $directoryId;
        }
        $iterName = $name . '.' . $ext;
        $i = 1;
        while ($this->db->exists($queryString, $iterName, $subParam)) {
            $iterName = $name . '-' . ++$i . '.' . $ext;
        }
        return $iterName;
    }