Maybe we should move this function as static method into a class defined in the file shared between the API and the maintenance script, also the serialization method used in maintenance. We can define also the common constants as const of that class, instead of globals.