53 $archiveName = $importableRevision->getArchiveName();
56 $this->logger->debug( __METHOD__ .
": Importing archived file as $archiveName" );
57 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
58 $localRepo, $archiveName );
60 $file = $localRepo->newFile( $importableRevision->getTitle() );
61 $file->load( IDBAccessObject::READ_LATEST );
62 $this->logger->debug( __METHOD__ .
': Importing new file as ' . $file->getName() );
63 if ( $file->exists() && $file->getTimestamp() > $importableRevision->getTimestamp() ) {
64 $archiveName = $importableRevision->getTimestamp() .
'!' . $file->getName();
65 $file = OldLocalFile::newFromArchiveName( $importableRevision->getTitle(),
66 $localRepo, $archiveName );
67 $this->logger->debug( __METHOD__ .
": File already exists; importing as $archiveName" );
71 $this->logger->debug( __METHOD__ .
': Bad file for ' . $importableRevision->getTitle() );
72 return $this->newNotOkStatus();
75 # Get the file source or download if necessary
76 $source = $importableRevision->getFileSrc();
77 $autoDeleteSource = $importableRevision->isTempSrc();
79 $source = $this->downloadSource( $importableRevision );
80 $autoDeleteSource =
true;
83 $this->logger->debug( __METHOD__ .
": Could not fetch remote file." );
84 return $this->newNotOkStatus();
88 if ( $autoDeleteSource ) {
89 $tmpFile->autocollect();
92 $sha1File = ltrim( sha1_file(
$source ),
'0' );
93 $sha1 = $importableRevision->getSha1();
94 if ( $sha1 && ( $sha1 !== $sha1File ) ) {
95 $this->logger->debug( __METHOD__ .
": Corrupt file $source." );
96 return $this->newNotOkStatus();
99 $user = $importableRevision->getUserObj()
100 ?: User::newFromName( $importableRevision->getUser(),
false );
102 # Do the actual upload
104 $status = $file->uploadOld(
106 $importableRevision->getTimestamp(),
107 $importableRevision->getComment(),
112 $status = $file->upload(
114 $importableRevision->getComment(),
115 $importableRevision->getComment(),
118 $importableRevision->getTimestamp(),
121 $this->shouldCreateNullRevision
125 if ( $status->isGood() ) {
126 $this->logger->debug( __METHOD__ .
": Successful" );
128 $this->logger->debug( __METHOD__ .
': failed: ' . $status->getHTML() );