| @@ -29,12 +29,28 @@ | ||
| 29 | 29 | /** |
| 30 | 30 | * Save the current instance. |
| 31 | 31 | * |
| 32 | 32 | * @return false|int |
| 33 | - * @throws ReflectionException If class is not defined. | |
| 34 | 33 | */ |
| 35 | - public function save() { | |
| 36 | - return self::get_orm()->save( $this ); | |
| 34 | + public function save(): bool|int { | |
| 35 | + try { | |
| 36 | + return self::get_orm()->save( $this ); | |
| 37 | + } catch ( \Throwable $e ) { | |
| 38 | + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | |
| 39 | + $this->log( | |
| 40 | + sprintf( | |
| 41 | + 'Failed to save %s: %s in %s:%d', | |
| 42 | + static::class, | |
| 43 | + $e->getMessage(), | |
| 44 | + $e->getFile(), | |
| 45 | + $e->getLine() | |
| 46 | + ), | |
| 47 | + 'db-save-error.log' | |
| 48 | + ); | |
| 49 | + } | |
| 50 | + | |
| 51 | + return false; | |
| 52 | + } | |
| 37 | 53 | } |
| 38 | 54 | |
| 39 | 55 | /** |
| 40 | 56 | * Retrieves the ORM instance from the dependency injection container. |