Beispiel #1
0
 /**
  * Generates a merge operation status report
  *
  * @param string $mergeId The merge operation's id
  * @return mmMergeStatusReport
  */
 public static function doMergeStatus($mergeHash)
 {
     $operation = mmMergeOperation::fetchByHash($mergeHash);
     if (!$operation instanceof mmMergeOperation) {
         $return['status'] = 'ko';
         $return['message'] = 'not_found';
     } else {
         $return['status'] = 'ok';
         $return['progress'] = $operation->progress();
         $return['file'] = $operation->commandObject->title;
     }
     return $return;
 }
Beispiel #2
0
    public function doSourcefileArchive()
    {
        $result = new ezcMvcResult();
        $nonExistingFiles = array();
        $hash = $this->hash;

        if ( $queueItem = mmMergeOperation::fetchByHash( $hash ) )
        {
            $status = 'ok';
            $message = '';
            $removed = array();
            $command = $queueItem->commandObject;
            if ( $command->conversionType == 'tvshow' )
            {
                $files = array_merge( $command->VideoFiles, $command->SubtitleFiles );
                foreach( $files as $file )
                {
                    $extension = pathinfo( $file['pathname'], PATHINFO_EXTENSION );
                    if ( ( $extension == 'mkv' or $extension == 'avi' ) &&
                        file_exists( $file['pathname']) &&
                        filesize( $file['pathname'] ) == 0 )
                    {
                        $result->variables['status'] = 'ko';
                        $result->variables['message'] = 'already_archived';
                        return $result;
                    }
                    if ( !file_exists( $file['pathname'] ) )
                    {
                        $nonExistingFiles[] = $file;
                    }
                    else
                    {
                        if ( !isset( $dummyFile ) )
                            $dummyFile = $file['pathname'];
                        $removed[] = $file['pathname'];
                        unlink( $file['pathname'] );
                    }
                }
                touch( $dummyFile );
            }
            else
            {
                $mainFile = $command->VideoFiles[0]['pathname'];
                if ( file_exists( $mainFile ) )
                {
                    $directory = dirname( $mainFile );
                    $files[] = glob( "$directory/*" );
                    try {
                        ezcBaseFile::removeRecursive( $directory );
                        $removed = $files;
                    } catch( ezcBaseFilePermissionException $e ) {
                        $status = 'ko';
                        $message = $e->getMessage();
                    }
                }
            }

            if ( !empty( $nonExistingFiles ) )
                $result->variables['messages'] = 'Some files were not found, see [not_found_files]';
            if ( $status === 'ok' )
            {
                $queueItem->status = mmMergeOperation::STATUS_ARCHIVED;
                ezcPersistentSessionInstance::get()->update( $queueItem );
            }
            $result->variables['status'] = $status;
            $result->variables['removed_files'] = $removed;
            $result->variables['not_found_files'] = $nonExistingFiles;
            $result->variables['message'] = $message;
        }
        else
        {
            // @todo Handle with exception
            $result->variables['status'] = 'ko';
            $result->variables['message'] = "No operation with hash $hash";
        }
        return $result;
    }