| Conditions | 8 |
| Paths | 6 |
| Total Lines | 40 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 14 | public function backup() { |
||
| 15 | |||
| 16 | if ( ! class_exists( 'ZipArchive' ) ) { |
||
| 17 | return false; |
||
| 18 | } |
||
| 19 | |||
| 20 | $zip = new \ZipArchive(); |
||
| 21 | |||
| 22 | // Attempt to create the zip file. |
||
| 23 | if ( $zip->open( $this->get_backup_filepath(), \ZIPARCHIVE::CREATE ) ) { |
||
| 24 | |||
| 25 | foreach ( $this->get_files() as $file ) { |
||
| 26 | |||
| 27 | // Create an empty directory for each directory in the filesystem |
||
| 28 | if ( $file->isDir() ) { |
||
| 29 | $zip->addEmptyDir( $file->getRelativePathname() ); |
||
| 30 | } |
||
| 31 | |||
| 32 | // Archive the file with a relative path |
||
| 33 | elseif ( $file->isFile() ) { |
||
| 34 | $zip->addFile( $file->getPathname(), $file->getRelativePathname() ); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | // Track any internal warnings |
||
| 39 | if ( $zip->status ) { |
||
| 40 | $this->warning( __CLASS__, $zip->status ); |
||
| 41 | } |
||
| 42 | |||
| 43 | if ( $zip->statusSys ) { |
||
| 44 | $this->warning( __CLASS__, $zip->statusSys ); |
||
| 45 | } |
||
| 46 | |||
| 47 | $zip->close(); |
||
| 48 | |||
| 49 | } |
||
| 50 | |||
| 51 | return $this->verify_backup(); |
||
| 52 | |||
| 53 | } |
||
| 54 | |||
| 56 |