14 public const DEFAULT_NAME =
'default';
24 $cache = \Cdb\Writer::open( $file );
25 $keys = array_keys( $changes );
26 $cache->set(
'#keys', TranslateUtils::serialize( $keys ) );
29 foreach ( $changes as $key => $change ) {
30 $value = TranslateUtils::serialize( $change->getAllModifications() );
31 $cache->set( $key, $value );
43 return preg_match(
'/^[a-z_-]{1,100}$/i', $name );
53 return TranslateUtils::cacheFile(
"messagechanges.$name.cdb" );
63 $reader = self::getCdbReader( $cdbPath );
64 if ( $reader ===
null ) {
65 return MessageSourceChange::loadModifications( [] );
68 $groups = TranslateUtils::deserialize( $reader->get(
'#keys' ) );
70 if ( !in_array( $groupId, $groups,
true ) ) {
71 throw new InvalidArgumentException(
"Group Id - '$groupId' not found in cdb file " .
72 "(path: $cdbPath)." );
75 return MessageSourceChange::loadModifications(
76 TranslateUtils::deserialize( $reader->get( $groupId ) )
88 $reader = self::getCdbReader( $cdbPath );
89 if ( $reader ===
null ) {
93 $groups = TranslateUtils::deserialize( $reader->get(
'#keys' ) );
96 foreach ( $groups as $id ) {
97 $allChanges[$id] = MessageSourceChange::loadModifications(
98 TranslateUtils::deserialize( $reader->get( $id ) )
101 $allChanges[$groupId] = $changes;
103 self::writeChanges( $allChanges, $cdbPath );
111 private static function getCdbReader( $cdbPath ) {
113 if ( !file_exists( $cdbPath ) ) {
117 return \Cdb\Reader::open( $cdbPath );
128 if ( !file_exists( $cdbPath ) ) {
132 $stat = stat( $cdbPath );
134 return $stat[
'mtime'];
144 $lastModifiedTime = self::getLastModifiedTime( $cdbPath );
146 if ( $lastModifiedTime ===
null ) {
147 throw new InvalidArgumentException(
"CDB file not found - $cdbPath" );
150 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.