15 public const DEFAULT_NAME =
'default';
25 $cache = \Cdb\Writer::open( $file );
26 $keys = array_keys( $changes );
27 $cache->set(
'#keys', Utilities::serialize( $keys ) );
30 foreach ( $changes as $key => $change ) {
31 $value = Utilities::serialize( $change->getAllModifications() );
32 $cache->set( $key, $value );
44 return preg_match(
'/^[a-z_-]{1,100}$/i', $name );
54 return Utilities::cacheFile(
"messagechanges.$name.cdb" );
64 $reader = self::getCdbReader( $cdbPath );
65 if ( $reader ===
null ) {
66 return MessageSourceChange::loadModifications( [] );
69 $groups = Utilities::deserialize( $reader->get(
'#keys' ) );
71 if ( !in_array( $groupId, $groups,
true ) ) {
72 throw new InvalidArgumentException(
"Group Id - '$groupId' not found in cdb file " .
73 "(path: $cdbPath)." );
76 return MessageSourceChange::loadModifications(
77 Utilities::deserialize( $reader->get( $groupId ) )
89 $reader = self::getCdbReader( $cdbPath );
90 if ( $reader ===
null ) {
94 $groups = Utilities::deserialize( $reader->get(
'#keys' ) );
97 foreach ( $groups as $id ) {
98 $allChanges[$id] = MessageSourceChange::loadModifications(
99 Utilities::deserialize( $reader->get( $id ) )
102 $allChanges[$groupId] = $changes;
104 self::writeChanges( $allChanges, $cdbPath );
112 private static function getCdbReader( $cdbPath ) {
114 if ( !file_exists( $cdbPath ) ) {
118 return \Cdb\Reader::open( $cdbPath );
129 if ( !file_exists( $cdbPath ) ) {
133 $stat = stat( $cdbPath );
135 return $stat[
'mtime'];
145 $lastModifiedTime = self::getLastModifiedTime( $cdbPath );
147 if ( $lastModifiedTime ===
null ) {
148 throw new InvalidArgumentException(
"CDB file not found - $cdbPath" );
151 return $lastModifiedTime <= $time;
static isModifiedSince( $cdbPath, $time)
Checks if the CDB file has been modified since the time given.
static getLastModifiedTime( $cdbPath)
Gets the last modified time for the CDB file.
static getGroupChanges( $cdbPath, $groupId)
Fetches changes for a group from the message change file.
static writeChanges(array $changes, $file)
Writes change array as a serialized file.
static getCdbPath( $name)
Get a full path to file in a known location.
static writeGroupChanges(MessageSourceChange $changes, $groupId, $cdbPath)
Writes changes for a group.
static isValidCdbName( $name)
Validate a name.