48 $archiveName = $importableRevision->getArchiveName();
51 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
52 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
53 $localRepo, $archiveName );
55 $file = $localRepo->newFile( $importableRevision->getTitle() );
56 $file->load( IDBAccessObject::READ_LATEST );
57 $this->logger->debug( __METHOD__ .
': Importing new file as ' . $file->getName() );
58 if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) {
59 $archiveName = $importableRevision->getTimestamp() .
'!' . $file->getName();
60 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
61 $localRepo, $archiveName );
62 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
66 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
67 return $this->newNotOkStatus();
70 # Get the file source or download if necessary
71 $source = $importableRevision->getFileSrc();
72 $autoDeleteSource = $importableRevision->isTempSrc();
74 $source = $this->downloadSource( $importableRevision );
75 $autoDeleteSource =
true;
78 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
79 return $this->newNotOkStatus();
83 if ( $autoDeleteSource ) {
84 $tmpFile->autocollect();
87 $sha1File = ltrim( sha1_file(
$source ),
'0' );
88 $sha1 = $importableRevision->getSha1();
89 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
90 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
91 return $this->newNotOkStatus();
94 $user = $importableRevision->getUserObj()
95 ?: User::newFromName( $importableRevision->getUser(),
false );
97 # Do the actual upload
99 $status = $file->uploadOld(
101 $importableRevision->getTimestamp(),
102 $importableRevision->getComment(),
107 $status = $file->upload(
109 $importableRevision->getComment(),
110 $importableRevision->getComment(),
113 $importableRevision->getTimestamp(),
116 $this->shouldCreateNullRevision
120 if ( $status->isGood() ) {
121 $this->logger->debug( __METHOD__ .
": Successful" );
123 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );