Imports the given issue file
@param int    $id    Issue file's ID
@param int    $oldId Old issue file's ID
@param Issue  $issue File's issue
@param string $slug  Journal's slug
540106
public function importIssueFile($id, $oldId, $issue, $slug)
    {
        $this->consoleOutput->writeln("Reading issue file #" . $id . "... ", true);

        $issueFileSql = "SELECT * FROM issue_files WHERE file_id = :id LIMIT 1";
        $issueFileStatement = $this->dbalConnection->prepare($issueFileSql);
        $issueFileStatement->bindValue('id', $id);
        $issueFileStatement->execute();

        $galleysSql = "SELECT galley_id, issue_id, locale, label FROM issue_galleys " .
            "WHERE issue_id = :issue_id AND file_id = :id";
        $galleysStatement = $this->dbalConnection->prepare($galleysSql);
        $galleysStatement->bindValue('issue_id', $oldId);
        $galleysStatement->bindValue('id', $id);
        $galleysStatement->execute();

        $pkpIssueFile = $issueFileStatement->fetch();
        $pkpGalleys = $galleysStatement->fetchAll();

        foreach ($pkpGalleys as $galley) {
            $locale = !empty($galley['locale']) ? mb_substr($galley['locale'], 0, 2, 'UTF-8') : 'en';
            $label = !empty($galley['label']) ? $galley['label'] : '-';
            $filename = sprintf('imported/%s/%s.%s',
                $galley['issue_id'],
                $galley['galley_id'],
                FileHelper::$mimeToExtMap[$pkpIssueFile['file_type']]);

            $issueFile = new IssueFile();
            $issueFile->setFile($filename);
            $issueFile->setIssue($issue);
            $issueFile->setVersion(0);
            $issueFile->setType(0);

            // Fill translatable fields
            $issueFile->setCurrentLocale($locale);
            $issueFile->setTitle($label);
            $issueFile->setDescription('-');

            $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => $filename]);

            if (!$history) {
                $history = new FileHistory();
                $history->setFileName($filename);
                $history->setOriginalName($pkpIssueFile['original_file_name']);
                $history->setType('issuefiles');
                $this->em->persist($history);
            }

            $source = sprintf('%s/issue/download/%s/%s', $slug, $galley['issue_id'], $galley['galley_id']);
            $target = sprintf('/../web/uploads/issuefiles/imported/%s/%s.%s',
                $galley['issue_id'],
                $galley['galley_id'],
                FileHelper::$mimeToExtMap[$pkpIssueFile['file_type']]);

            $pendingDownload = new PendingDownload();
            $pendingDownload->setSource($source);
            $pendingDownload->setTarget($target);

            $this->em->persist($pendingDownload);
            $this->em->persist($issueFile);
        }
    }
1302998
public function importJournalUsers($newJournalId, $oldJournalId, $userImporter)
    {
        $this->em->clear();
        $journal = $this->em->getRepository('VipaJournalBundle:Journal')->find($newJournalId);

        $roleMap = [
            '1'      => "ROLE_ADMIN",
            '2'      => "ROLE_USER",
            '10'     => "ROLE_JOURNAL_MANAGER",
            '100'    => "ROLE_EDITOR",
            '200'    => 'ROLE_SECTION_EDITOR',
            '300'    => 'ROLE_LAYOUT_EDITOR',
            '1000'   => "ROLE_REVIEWER",
            '2000'   => 'ROLE_COPYEDITOR',
            '3000'   => "ROLE_PROOFREADER",
            '10000'  => "ROLE_AUTHOR",
            '100000' => 'ROLE_READER',
            '200000' => "ROLE_SUBSCRIPTION_MANAGER",
        ];

        // Replace role names with role entities
        foreach ($roleMap as $id => $name) {
            $role = $this->em->getRepository('VipaUserBundle:Role')->findOneBy(['role' => $name]);

            if (!$role) {
                $role = new Role();
                $role->setName($name);
                $role->setRole($name);
            }

            $roleMap[$id] = $role;
        }

        $roleStatement = $this->dbalConnection->prepare(
            "SELECT roles.journal_id, roles.user_id, roles.role_id, users.email FROM " .
            "roles JOIN users ON roles.user_id = users.user_id WHERE roles.journal_id" .
            "= :id " . ImportHelper::spamUsersFilterSql()
        );

        $roleStatement->bindValue('id', $oldJournalId);
        $roleStatement->execute();
        $roles = $roleStatement->fetchAll();

        $cache = array();

        foreach ($roles as $role) {
            $email = $role['email'];

            // Put the user from DB to cache
            if (empty($cache[$email]['user'])) {
                $cache[$email]['user'] = $this->em
                    ->getRepository('VipaUserBundle:User')
                    ->findOneBy(['email' => $email]);
            }

            // Create the user and put it to cache
            if(empty($cache[$email]['user'])) {
                $cache[$email]['user'] = $userImporter
                    ->importUser($role['user_id'], false);
            }

            /** @var JournalUser $journalUser */
            $journalUser = $this->getJournalUser($cache, $email, $journal);
            $journalUser->addRole($roleMap[dechex($role['role_id'])]);
        }

        $this->consoleOutput->writeln("Writing data...");
        $this->em->flush();
        $this->consoleOutput->writeln("Imported users.");
    }
1368546
public function prepareSlugForPersist($title, $slug, $id=false)
    {
        $separator = '-';

        if ($slug == "")
        {
            // No slug.. so this is a "create" form; or, the slug was deleted accidentally and so needs to be regenerated

            // Convert all dashes/underscores into separator
            $flip = $separator == '-' ? '_' : '-';

            // wash the title
            $title = html_entity_decode($title);
            $title = strip_tags($title);
            $title = filter_var($title, FILTER_SANITIZE_STRING);
            // remove the encoded blank chars
            $title = str_replace("\xc2\xa0",'',$title);
            // remove encoded apostrophe
            $title = str_replace("&#39;",'',$title);
            $title = trim($title);

            $slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);

            // Remove all characters that are not the separator, letters, numbers, or whitespace.
            $slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));

            // Replace all separator characters and whitespace by a single separator
            $slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);

            // well, is another record using this slug already? Let's return a record count, so we can use the count number...
            $rowCount = $this->doesSlugAlreadyExist($slug);

            if ($rowCount > 0)
            {
                // yes, this slug does exist already, so let's append this slug to make it different from what already exists.
                ++$rowCount;
                return $slug.$rowCount;
            }

            // no, this slug does not yet exist, so let's use it as-is...
            return $slug;
        }


        // Ah, so a slug was entered. So coming from an "edit" form...

        // remove the encoded blank chars
        $slug = str_replace("\xc2\xa0",'',$slug);

        // remove encoded apostrophe
        $slug = str_replace("&#39;",'',$slug);

        $slug = trim($slug);
        $slug = strtolower($slug);
        $slug = strip_tags($slug);
        $slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);


        // if this slug is a different slug manually entered into the edit form, then process it further
        if (!$this->isManuallyChangedSlugInEditForm($slug, $id)) {
            return $slug;
        }

        // so this slug does belong to the existing ID, but is different than the slug in the database...

        // well, is another record using this slug already? Let's return a record count, so we can use the count number...
        $rowCount = $this->doesSlugAlreadyExist($slug);

        if ($rowCount > 0)
        {
            // yes, this slug does exist already, so let's append this slug to make it different from what already exists.
            ++$rowCount;
            return $slug.$rowCount;
        }

        // no, this slug does not yet exist, so let's use it as-is...
        return $slug;
    }
1247838
public function import($id, $directoryPath)
    {
        $this->ids[] = $id;
        return $this->getInternalStorage()->import($id, $directoryPath);
    }
240132
protected function flaggedForImport( $id ) {

		$chapters = getset( '_POST', 'chapters' );

		if ( ! is_array( $chapters ) ) {
			return false;
		}

		if ( ! isset( $chapters[ $id ] ) ) {
			return false;
		}

		if ( ! isset( $chapters[ $id ]['import'] ) ) {
			return false;
		}

		return ( 1 === (int) $chapters[ $id ]['import'] ? true : false );
	}
12826
public function importArticleStatistic($oldId, $newId)
    {
        $article = $this->em->getRepository('VipaJournalBundle:Article')->find($newId);

        if (!$article) {
            $this->consoleOutput->writeln("Couldn't find #" . $newId . " on the new database.");
            return;
        }

        $this->consoleOutput->writeln("Reading view statistics for #" . $oldId . "...");
        $viewStatsSql = "SELECT DATE(view_time) AS date, COUNT(*) as view FROM " .
            "article_view_stats WHERE article_id = :id GROUP BY DATE(view_time)";
        $viewStatsStatement = $this->dbalConnection->prepare($viewStatsSql);
        $viewStatsStatement->bindValue('id', $oldId);
        $viewStatsStatement->execute();

        $this->consoleOutput->writeln("Reading download statistics for #" . $oldId . "...");
        $downloadStatsSql = "SELECT DATE(download_time) AS date, COUNT(*) as download FROM " .
            "article_download_stats WHERE article_id = :id GROUP BY DATE(download_time)";
        $downloadStatsStatement = $this->dbalConnection->prepare($downloadStatsSql);
        $downloadStatsStatement->bindValue('id', $oldId);
        $downloadStatsStatement->execute();
        
        $pkpViewStats = $viewStatsStatement->fetchAll();
        $pkpDownloadStats = $downloadStatsStatement->fetchAll();
        foreach ($pkpViewStats as $stat) {
            $articleFileStatistic = new ArticleStatistic();
            $articleFileStatistic->setArticle($article);
            $articleFileStatistic->setDate(DateTime::createFromFormat('Y-m-d', $stat['date']));
            $articleFileStatistic->setView($stat['view']);
            $this->em->persist($articleFileStatistic);
        }

        if (!$article->getArticleFiles()->isEmpty()) {
            foreach ($pkpDownloadStats as $stat) {
                $articleFileStatistic = new ArticleFileStatistic();
                $articleFileStatistic->setArticleFile($article->getArticleFiles()->first());
                $articleFileStatistic->setDate(DateTime::createFromFormat('Y-m-d', $stat['date']));
                $articleFileStatistic->setDownload($stat['download']);
                $this->em->persist($articleFileStatistic);
            }
        }

        $this->em->flush();
    }
1059509
public function run($cid = null, $fid = null, $id = null, $slug = null)
    {
        $thread = $this->getThread($cid, $fid, $id, $slug);
        if (empty($thread)) {
            $this->controller->error(Yii::t('podium/flash', 'Sorry! We can not find the thread you are looking for.'));
            return $this->controller->redirect(['forum/index']);
        }

        if (!User::can($this->permission, ['item' => $thread])) {
            $this->controller->error(Yii::t('podium/flash', 'Sorry! You do not have the required permission to perform this action.'));
            return $this->controller->redirect(['forum/index']);
        }

        if (call_user_func([$thread, $this->switcher])) {
            $this->controller->success($thread->{$this->boolAttribute} ? $this->onMessage : $this->offMessage);
        } else {
            $this->controller->error(Yii::t('podium/flash', 'Sorry! There was an error while updating the thread.'));
        }
        return $this->controller->redirect([
            'forum/thread',
            'cid' => $thread->forum->category->id,
            'fid' => $thread->forum->id,
            'id' => $thread->id,
            'slug' => $thread->slug
        ]);
    }
1373954
public function updateIDValue(&$id)
    {
        $owner = $this->owner;
        if ($owner->Title) {
            $id = Convert::raw2url($owner->Title);
        }
    }
1294965
def get(cls, issue_id):
        
        res = Issue.get(issue_id, IssueType.get(cls.issue_type).issue_type_id)
        return cls(res) if res else None
235434
public function handleDelete(int $id): void
	{
		if ($this->isAjax()) {
			$page = $this->orm->pages->getById($id);
			$parent = $page->parent;
			$this->orm->pages->removeAndFlush($page);
			if ($parent !== null) {
				$this['list']->setDataSource($this->orm->pages->findById($parent->id));
				$this['list']->redrawItem($parent->id);
			} else {
				$this['list']->redrawControl();
			}
		} else {
			$this->terminate();
		}
	}
992818
public function actionShow($id, $slug)
    {
        $model = $this->model->node($id);
        if (empty($model) || !$model->is_visible || $model->slug != $slug) {
            throw new NotFoundHttpException(Yii::t($this->tcModule, 'Content not found'));
        }
        
        return $this->actionView($id, true, null, true, false, true);
    }
611132
public function importJournal($id)
    {
        $this->consoleOutput->writeln("Importing the journal...");

        $journalSql = "SELECT path, primary_locale FROM journals WHERE journal_id = :id LIMIT 1";
        $journalStatement = $this->dbalConnection->prepare($journalSql);
        $journalStatement->bindValue('id', $id);
        $journalStatement->execute();

        $settingsSql = "SELECT locale, setting_name, setting_value FROM journal_settings WHERE journal_id = :id";
        $settingsStatement = $this->dbalConnection->prepare($settingsSql);
        $settingsStatement->bindValue('id', $id);
        $settingsStatement->execute();

        $pkpJournal = $journalStatement->fetch();
        $pkpSettings = $settingsStatement->fetchAll();
        $primaryLocale = $pkpJournal['primary_locale'];
        $languageCode = mb_substr($primaryLocale, 0, 2, 'UTF-8');

        !$pkpJournal && die('Journal not found.' . PHP_EOL);
        $this->consoleOutput->writeln("Reading journal settings...");

        foreach ($pkpSettings as $setting) {
            $locale = !empty($setting['locale']) ? mb_substr($setting['locale'], 0, 2, 'UTF-8') : $languageCode;
            $name = $setting['setting_name'];
            $value = $setting['setting_value'];
            $this->settings[$locale][$name] = $value;
        }

        $this->journal = new Journal();
        $this->journal->setStatus(1);
        $this->journal->setSlug($pkpJournal['path']);

        // Fill translatable fields in all available languages except the primary one
        foreach ($this->settings as $fieldLocale => $fields) {
            if ($fieldLocale === $languageCode) {
                // We will fill fields of the primary language later.
                continue;
            }

            $this->journal->setCurrentLocale(mb_substr($fieldLocale, 0, 2, 'UTF-8'));

            !empty($fields['title']) ?
                $this->journal->setTitle($fields['title']) :
                $this->journal->setTitle('Unknown Journal');

            !empty($fields['description']) ?
                $this->journal->setDescription($fields['description']) :
                $this->journal->setDescription('-');
        }

        $this->journal->setCurrentLocale($languageCode);

        // Fill fields for the primary language
        !empty($this->settings[$languageCode]['title']) ?
            $this->journal->setTitle($this->settings[$languageCode]['title']) :
            $this->journal->setTitle('Unknown Journal');

        !empty($this->settings[$languageCode]['description']) ?
            $this->journal->setDescription($this->settings[$languageCode]['description']) :
            $this->journal->setDescription('-');

        !empty($this->settings[$languageCode]['journalPageFooter']) ?
            $this->journal->setFooterText($this->settings[$languageCode]['journalPageFooter']) :
            $this->journal->setFooterText(null);

        !empty($this->settings[$languageCode]['printIssn']) && count($this->settings[$languageCode]['printIssn']) == 9 ?
            $this->journal->setIssn($this->settings[$languageCode]['printIssn']) :
            $this->journal->setIssn('');

        !empty($this->settings[$languageCode]['onlineIssn']) && count($this->settings[$languageCode]['onlineIssn']) == 9 ?
            $this->journal->setEissn($this->settings[$languageCode]['onlineIssn']) :
            $this->journal->setEissn('');

        $date = sprintf('%d-01-01 00:00:00',
            !empty($this->settings[$languageCode]['initialYear']) ?
                $this->settings[$languageCode]['initialYear'] : '2015');
        $this->journal->setFounded(DateTime::createFromFormat('Y-m-d H:i:s', $date));

        // Set view and download counts
        !empty($this->settings[$languageCode]['total_views']) ?
            $this->journal->setViewCount($this->settings[$languageCode]['total_views']) :
            $this->journal->setViewCount(0);
        !empty($this->settings[$languageCode]['total_downloads']) ?
            $this->journal->setDownloadCount($this->settings[$languageCode]['total_downloads']) :
            $this->journal->setDownloadCount(0);
        !empty($this->settings[$languageCode]['homeHeaderTitleImage']) ?
            $header = unserialize($this->settings[$languageCode]['homeHeaderTitleImage']) :
            $header = null;

        if ($header) {
            $baseDir = '/../web/uploads/journal/imported/';
            $croppedBaseDir = '/../web/uploads/journal/croped/imported/';
            $headerPath = $id . '/' . $header['uploadName'];

            $pendingDownload = new PendingDownload();
            $pendingDownload
                ->setSource('public/journals/' . $headerPath)
                ->setTarget($baseDir . $headerPath)
                ->setTag('journal-header');

            $croppedPendingDownload = new PendingDownload();
            $croppedPendingDownload
                ->setSource('public/journals/' . $headerPath)
                ->setTarget($croppedBaseDir . $headerPath)
                ->setTag('journal-header');

            $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => 'imported/' . $headerPath]);

            if (!$history) {
                $history = new FileHistory();
                $history->setFileName('imported/' . $headerPath);
                $history->setOriginalName('imported/' . $headerPath);
                $history->setType('journal');
            }

            $this->em->persist($croppedPendingDownload);
            $this->em->persist($pendingDownload);
            $this->em->persist($history);
            $this->journal->setHeader('imported/' . $headerPath);
        }

        $subjects = $this->importSubjects($languageCode);

        foreach ($subjects as $subject) {
            $this->journal->addSubject($subject);
        }

        // Set publisher
        !empty($this->settings[$languageCode]['publisherInstitution']) ?
            $this->importAndSetPublisher($this->settings[$languageCode]['publisherInstitution'], $languageCode) :
            $this->journal->setPublisher($this->getUnknownPublisher($languageCode));

        // Use existing languages or create if needed
        $language = $this->em
            ->getRepository('VipaJournalBundle:Lang')
            ->findOneBy(['code' => $languageCode]);
        $this->journal->setMandatoryLang($language ? $language : $this->createLanguage($languageCode));
        $this->journal->addLanguage($language ? $language : $this->createLanguage($languageCode));

        $this->importContacts($languageCode);
        $this->importSubmissionChecklist($languageCode);

        $this->consoleOutput->writeln("Read journal's settings.");
        $this->em->beginTransaction(); // Outer transaction

        try {
            $this->em->beginTransaction(); // Inner transaction
            $this->em->persist($this->journal);
            $this->em->flush();
            $this->em->commit();
        } catch (Exception $exception) {
            $this->em->rollback();
            throw $exception;
        }

        $this->consoleOutput->writeln("Imported journal #" . $id);

        // Those below also create their own inner transactions
        $createdSections = $this->sectionImporter->importJournalSections($id, $this->journal->getId());
        $createdIssues = $this->issueImporter->importJournalIssues($id, $this->journal->getId(), $createdSections);
        $this->articleImporter->importJournalArticles($id, $this->journal->getId(), $createdIssues, $createdSections);
        $this->journalPageImporter->importPages($id, $this->journal->getId());

        $createdBoards = $this->boardImporter->importBoards($id, $this->journal->getId());

        foreach ($createdBoards as $oldBoardId => $newBoardId) {
            $this->boardMemberImporter->importBoardMembers($oldBoardId, $newBoardId);
        }

        $this->importAboutPage();

        $map = new ImportMap($id, $this->journal->getId(), Journal::class);
        $this->em->persist($map);
        $this->em->flush();
        $this->em->commit();

        return ['new' => $this->journal->getId(), 'old' => $id];
    }
1083072
def get(issue_id, issue_type_id):
        
        return db.Issue.find_one(
            Issue.issue_id == issue_id,
            Issue.issue_type_id == issue_type_id
        )
678353
public function importArticleFile($pkpArticleFile, $oldArticleId, $article, $slug)
    {
        $this->consoleOutput->writeln("Reading article file #" . $pkpArticleFile['file_id'] . "... ", true);

        $galleysSql = "SELECT galley_id, article_id, locale, label FROM article_galleys " .
            "WHERE article_id = :article_id AND file_id = :id";
        $galleysStatement = $this->dbalConnection->prepare($galleysSql);
        $galleysStatement->bindValue('article_id', $oldArticleId);
        $galleysStatement->bindValue('id', $pkpArticleFile['file_id']);
        $galleysStatement->execute();

        $pkpGalleys = $galleysStatement->fetchAll();

        foreach ($pkpGalleys as $galley) {
            $locale = !empty($galley['locale']) ? mb_substr($galley['locale'], 0, 2, 'UTF-8') : 'en';
            $label = !empty($galley['label']) ? $galley['label'] : '-';
            $version = !empty($pkpArticleFile['revision']) ? $pkpArticleFile['revision'] : 0;
            $filename = sprintf('imported/%s/%s.%s',
                $galley['article_id'],
                $galley['galley_id'],
                FileHelper::$mimeToExtMap[$pkpArticleFile['file_type']]);

            $articleFile = new ArticleFile();
            $articleFile->setFile($filename);
            $articleFile->setArticle($article);
            $articleFile->setVersion($version);
            $articleFile->setTitle($label);
            $articleFile->setLangCode($locale);
            $articleFile->setDescription('-');
            $articleFile->setType(ArticleFileParams::FULL_TEXT);

            $history = $this->em->getRepository(FileHistory::class)->findOneBy(['fileName' => $filename]);

            if (!$history) {
                $history = new FileHistory();
                $history->setFileName($filename);
                $history->setOriginalName($pkpArticleFile['original_file_name']);
                $history->setType('articlefiles');
                $this->em->persist($history);
            }

            $source = sprintf('%s/article/download/%s/%s', $slug, $galley['article_id'], $galley['galley_id']);
            $target = sprintf('/../web/uploads/articlefiles/imported/%s/%s.%s',
                $galley['article_id'],
                $galley['galley_id'],
                FileHelper::$mimeToExtMap[$pkpArticleFile['file_type']]);

            $pendingDownload = new PendingDownload();
            $pendingDownload->setSource($source);
            $pendingDownload->setTarget($target);

            $this->em->persist($pendingDownload);
            $this->em->persist($articleFile);
        }
    }
631847
public function getThread($cid, $fid, $id, $slug)
    {
        if ($this->_thread === null) {
            $this->_thread = (new ThreadVerifier([
                    'categoryId' => $cid,
                    'forumId' => $fid,
                    'threadId' => $id,
                    'threadSlug' => $slug
                ]))->verify();
        }
        return $this->_thread;
    }
151285
public function entry($slug, $id)
    {
        // AUTHORIZE ... COMES HERE
        $form = $this->form->getBySlug($slug);
        $entry = $this->formEntry->getById($id);
        return view('chuckcms::backend.forms.entries.index', compact('form', 'entry'));
    }
149772
public function move_files($questionid, $oldcontextid, $newcontextid) {
        $fs = get_file_storage();
        $fs->move_area_files_to_new_context($oldcontextid,
                $newcontextid, 'question', 'questiontext', $questionid);
        $fs->move_area_files_to_new_context($oldcontextid,
                $newcontextid, 'question', 'generalfeedback', $questionid);
    }