- public static function createTableName(string $version, string $name): string {
- [$major, $minor] = explode('.', $version);
- return sprintf('civicrm_snap_v%s_%s_%s', $major, $minor, $name);
+ public static function createTableName(string $owner, string $version, string $name): string {
+ $versionParts = explode('.', $version);
+ if (count($versionParts) !== 2) {
+ throw new \CRM_Core_Exception("Snapshot support is currently only defined for two-part version (MAJOR.MINOR). Found ($version).");
+ // If you change this, be sure to consider `cleanupTask()` as well.
+ // One reason you might change it -- if you were going to track with the internal schema-numbers from an extension.
+ // Of course, you could get similar effect with "0.{$schemaNumber}" eg "5002" ==> "0.5002"
+ }
+ $versionExpr = ($versionParts[0] . '_' . $versionParts[1]);
+
+ $table = sprintf('snap_%s_v%s_%s', $owner, $versionExpr, $name);
+ if (!preg_match(';^[a-z0-9_]+$;', $table)) {
+ throw new CRM_Core_Exception("Malformed snapshot name ($table)");
+ }
+ if (strlen($table) > 64) {
+ throw new CRM_Core_Exception("Snapshot name is too long ($table)");
+ }
+
+ return $table;