Automattic\WooCommerce\Internal\PushNotifications\DataStores
NotificationPreferencesDataStore::migrate
Upgrade an envelope to the current schema version.
Pure transformation — does not persist. Missing or malformed preferences entries are replaced with an empty array; the service layer is responsible for filling in defaults from the empty case.
Method of the class: NotificationPreferencesDataStore{}
No Hooks.
Returns
Array. Envelope upgraded to self::CURRENT_SCHEMA_VERSION.
Usage
$NotificationPreferencesDataStore = new NotificationPreferencesDataStore(); $NotificationPreferencesDataStore->migrate( $data, $from_version ): array;
- $data(array) (required)
- The stored envelope (expected keys:
schema_version,preferences). - $from_version(int) (required)
- The schema version currently on disk.
Changelog
| Since 10.8.0 | Introduced. |
NotificationPreferencesDataStore::migrate() NotificationPreferencesDataStore::migrate code WC 10.9.1
public function migrate( array $data, int $from_version ): array {
// Parameter reserved for future schema migrations.
unset( $from_version );
$preferences = isset( $data['preferences'] ) && is_array( $data['preferences'] )
? $data['preferences']
: array();
// For v1 the envelope shape is stable; we only normalize the version tag.
return array(
'schema_version' => self::CURRENT_SCHEMA_VERSION,
'preferences' => $preferences,
);
}