1616namespace DatabaseBackup \Utility ;
1717
1818use Cake \Core \Configure ;
19- use Tools \ Exceptionist ;
19+ use LogicException ;
2020use Tools \Filesystem ;
2121
2222/**
@@ -68,7 +68,7 @@ class BackupExport extends AbstractBackupUtility
6868 * @param string|null $compression Compression type name
6969 * @return $this
7070 * @see https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupExport-utility#compression
71- * @throws \ErrorException
71+ * @throws \LogicException
7272 * @noinspection PhpMissingReturnTypeInspection
7373 */
7474 public function compression (?string $ compression )
@@ -77,7 +77,9 @@ public function compression(?string $compression)
7777
7878 if ($ compression ) {
7979 $ this ->extension = (string )array_search ($ compression , $ this ->getValidCompressions ());
80- Exceptionist::isTrue ($ this ->extension , __d ('database_backup ' , 'Invalid compression type ' ));
80+ if (!$ this ->extension ) {
81+ throw new LogicException (__d ('database_backup ' , 'Invalid compression type ' ));
82+ }
8183 }
8284 $ this ->compression = $ compression ;
8385
@@ -91,7 +93,7 @@ public function compression(?string $compression)
9193 * @param string $filename Filename. It can be an absolute path and may contain patterns
9294 * @return $this
9395 * @see https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupExport-utility#filename
94- * @throws \ErrorException|\Tools\Exception\NotWritableException
96+ * @throws \LogicException
9597 * @noinspection PhpMissingReturnTypeInspection
9698 */
9799 public function filename (string $ filename )
@@ -107,11 +109,15 @@ public function filename(string $filename)
107109 ], $ filename );
108110
109111 $ filename = $ this ->getAbsolutePath ($ filename );
110- Exceptionist::isWritable (dirname ($ filename ));
111- Exceptionist::isTrue (!file_exists ($ filename ), __d ('database_backup ' , 'File `{0}` already exists ' , $ filename ));
112-
113- //Checks for extension
114- Exceptionist::isTrue ($ this ->getExtension ($ filename ), __d ('database_backup ' , 'Invalid `{0}` file extension ' , pathinfo ($ filename , PATHINFO_EXTENSION )));
112+ if (!is_writable (dirname ($ filename ))) {
113+ throw new LogicException (__d ('database_backup ' , 'File or directory ` ' . dirname ($ filename ) . '` is not writable ' ));
114+ }
115+ if (file_exists ($ filename )) {
116+ throw new LogicException (__d ('database_backup ' , 'File `{0}` already exists ' , $ filename ));
117+ }
118+ if (!$ this ->getExtension ($ filename )) {
119+ throw new LogicException (__d ('database_backup ' , 'Invalid `{0}` file extension ' , pathinfo ($ filename , PATHINFO_EXTENSION )));
120+ }
115121
116122 //Sets the compression
117123 $ this ->compression ($ this ->getCompression ($ filename ));
@@ -156,7 +162,8 @@ public function send(?string $recipient = null)
156162 * - `Backup.beforeExport`: will be triggered before export;
157163 * - `Backup.afterExport`: will be triggered after export.
158164 * @return string|false Filename path on success or `false` if the `Backup.beforeExport` event is stopped
159- * @throws \Exception
165+ * @throws \LogicException
166+ * @throws \ReflectionException
160167 * @see \DatabaseBackup\Driver\AbstractDriver::afterExport()
161168 * @see \DatabaseBackup\Driver\AbstractDriver::beforeExport()
162169 * @see https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupExport-utility#export
@@ -180,7 +187,9 @@ public function export()
180187
181188 //Exports
182189 $ Process = $ this ->getProcess ($ this ->getDriver ()->getExportExecutable ($ filename ));
183- Exceptionist::isTrue ($ Process ->isSuccessful (), __d ('database_backup ' , 'Export failed with error message: `{0}` ' , rtrim ($ Process ->getErrorOutput ())));
190+ if (!$ Process ->isSuccessful ()) {
191+ throw new LogicException (__d ('database_backup ' , 'Export failed with error message: `{0}` ' , rtrim ($ Process ->getErrorOutput ())));
192+ }
184193 Filesystem::instance ()->chmod ($ filename , Configure::read ('DatabaseBackup.chmod ' ));
185194
186195 //Dispatches the `Backup.afterExport` event implemented by the driver
0 commit comments