public static function fix_revision_values(array $versions) {

        $byrev = [];

        foreach ($versions as $version) {
            if ($version->revision === '') {
                $version->revision = userdate($version->timecreated, get_string('strftimedate', 'core_langconfig'));
            }
            $byrev[$version->revision][$version->id] = true;
        }

        foreach ($byrev as $origrevision => $versionids) {
            $cnt = count($byrev[$origrevision]);
            if ($cnt > 1) {
                foreach ($versionids as $versionid => $unused) {
                    foreach ($versions as $version) {
                        if ($version->id == $versionid) {
                            $version->revision = $version->revision.' - v'.$cnt;
                            $cnt--;
                            break;
                        }
                    }
                }
            }
        }
    }
public static function fix_revision_values(array $versions) {

        $byrev = [];

        foreach ($versions as $version) {
            if ($version->revision === '') {
                $version->revision = userdate($version->timecreated, get_string('strftimedate', 'core_langconfig'));
            }
            $byrev[$version->revision][$version->id] = true;
        }

        foreach ($byrev as $origrevision => $versionids) {
            $cnt = count($byrev[$origrevision]);
            if ($cnt > 1) {
                foreach ($versionids as $versionid => $unused) {
                    foreach ($versions as $version) {
                        if ($version->id == $versionid) {
                            $version->revision = $version->revision.' - v'.$cnt;
                            $cnt--;
                            break;
                        }
                    }
                }
            }
        }
    }
public static function fix_revision_values ( array $ versions ) { $ byrev = [ ] ; foreach ( $ versions as $ version ) { if ( $ version -> revision === '' ) { $ version -> revision = userdate ( $ version -> timecreated , get_string ( 'strftimedate' , 'core_langconfig' ) ) ; } $ byrev [ $ version -> revision ] [ $ version -> id ] = true ; } foreach ( $ byrev as $ origrevision => $ versionids ) { $ cnt = count ( $ byrev [ $ origrevision ] ) ; if ( $ cnt > 1 ) { foreach ( $ versionids as $ versionid => $ unused ) { foreach ( $ versions as $ version ) { if ( $ version -> id == $ versionid ) { $ version -> revision = $ version -> revision . ' - v' . $ cnt ; $ cnt -- ; break ; } } } } } }
Make sure that each version has a unique revision value.

Empty value are replaced with a timecreated date. Duplicates are suffixed with v1, v2, v3, ... etc.

@param array $versions List of objects with id, timecreated and revision properties
Make sure that each version has a unique revision value .