当前位置: 首页>>代码示例>>PHP>>正文


PHP modX::exec方法代码示例

本文整理汇总了PHP中modX::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::exec方法的具体用法?PHP modX::exec怎么用?PHP modX::exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在modX的用法示例。


在下文中一共展示了modX::exec方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: move

 /**
  * Move a thread to a new board
  *
  * @param int $boardId
  * @return boolean True if successful
  */
 public function move($boardId)
 {
     $oldBoard = $this->getOne('Board');
     $newBoard = is_object($boardId) && $boardId instanceof disBoard ? $boardId : $this->xpdo->getObject('disBoard', $boardId);
     if (!$oldBoard || !$newBoard) {
         return false;
     }
     $this->addOne($newBoard);
     if ($this->save()) {
         /* readjust all posts */
         $posts = $this->getMany('Posts');
         foreach ($posts as $post) {
             $post->set('board', $newBoard->get('id'));
             $post->save();
         }
         /* adjust old board topics/reply counts */
         $oldBoard->set('num_topics', $oldBoard->get('num_topics') - 1);
         $replies = $oldBoard->get('num_replies') - $this->get('replies');
         $oldBoard->set('num_replies', $replies);
         $total_posts = $oldBoard->get('total_posts') - $this->get('replies') - 1;
         $oldBoard->set('total_posts', $total_posts);
         /* recalculate latest post */
         $oldBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $oldBoard->get('last_post')));
         if ($oldBoardLastPost && $oldBoardLastPost->get('id') == $this->get('post_last')) {
             $newLastPost = $oldBoard->get2ndLatestPost();
             if ($newLastPost) {
                 $oldBoard->set('last_post', $newLastPost->get('id'));
                 $oldBoard->addOne($newLastPost, 'LastPost');
             }
         }
         $oldBoard->save();
         /* adjust new board topics/reply counts */
         $newBoard->set('num_topics', $oldBoard->get('num_topics') - 1);
         $replies = $newBoard->get('num_replies') + $this->get('replies');
         $newBoard->set('num_replies', $replies);
         $total_posts = $newBoard->get('total_posts') + $this->get('replies') + 1;
         $newBoard->set('total_posts', $total_posts);
         /* recalculate latest post */
         $newBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $newBoard->get('last_post')));
         $thisThreadPost = $this->getOne('LastPost');
         if ($newBoardLastPost && $thisThreadPost && $newBoardLastPost->get('createdon') < $thisThreadPost->get('createdon')) {
             $newBoard->set('last_post', $thisThreadPost->get('id'));
             $newBoard->addOne($thisThreadPost, 'LastPost');
         }
         $newBoard->save();
         /* Update ThreadRead board field */
         $this->xpdo->exec('UPDATE ' . $this->xpdo->getTableName('disThreadRead') . '
             SET ' . $this->xpdo->escape('board') . ' = ' . $newBoard->get('id') . '
             WHERE ' . $this->xpdo->escape('thread') . ' = ' . $this->get('id') . '
         ');
         /* clear caches */
         if (!defined('DISCUSS_IMPORT_MODE')) {
             $this->xpdo->getCacheManager();
             $this->xpdo->cacheManager->delete('discuss/thread/' . $this->get('id'));
             $this->xpdo->cacheManager->delete('discuss/board/' . $newBoard->get('id'));
             $this->xpdo->cacheManager->delete('discuss/board/' . $oldBoard->get('id'));
         }
     }
     return true;
 }
开发者ID:oneismore,项目名称:Discuss,代码行数:66,代码来源:disthread.class.php

示例2: updateChildrenURIs

 /**
  * Update all Articles URIs to reflect the new blog alias
  *
  * @param string $newAlias
  * @param string $oldAlias
  * @return bool
  */
 public function updateChildrenURIs($newAlias, $oldAlias)
 {
     $useMultiByte = $this->getOption('use_multibyte', null, false) && function_exists('mb_strlen');
     $encoding = $this->getOption('modx_charset', null, 'UTF-8');
     $oldAliasLength = ($useMultiByte ? mb_strlen($oldAlias, $encoding) : strlen($oldAlias)) + 1;
     $uriField = $this->xpdo->escape('uri');
     $sql = 'UPDATE ' . $this->xpdo->getTableName('Article') . '
         SET ' . $uriField . ' = CONCAT("' . $newAlias . '",SUBSTRING(' . $uriField . ',' . $oldAliasLength . '))
         WHERE
             ' . $this->xpdo->escape('parent') . ' = ' . $this->get('id') . '
         AND SUBSTRING(' . $uriField . ',1,' . $oldAliasLength . ') = "' . $oldAlias . '/"';
     $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, $sql);
     $this->xpdo->exec($sql);
     return true;
 }
开发者ID:raadhuis,项目名称:modx-basic,代码行数:22,代码来源:articlescontainer.class.php

示例3: rankResourceImages

 /**
  * @param $resource_id
  */
 public function rankResourceImages($resource_id)
 {
     $q = $this->modx->newQuery('msResourceFile', array('resource_id' => $resource_id, 'parent' => 0, 'type' => 'image'));
     $q->select('id');
     $q->sortby('rank ASC, createdon', 'ASC');
     if ($q->prepare() && $q->stmt->execute()) {
         $sql = '';
         $table = $this->modx->getTableName('msResourceFile');
         if ($ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN)) {
             foreach ($ids as $k => $id) {
                 $sql .= "UPDATE {$table} SET `rank` = '{$k}' WHERE `type` = 'image' AND (`id` = '{$id}' OR `parent` = '{$id}');";
             }
         }
         $sql .= "ALTER TABLE {$table} ORDER BY `rank` ASC;";
         $this->modx->exec($sql);
     }
 }
开发者ID:sin4end,项目名称:ms2Gallery,代码行数:20,代码来源:ms2gallery.class.php

示例4: rankResourceImages

 /**
  * Accurate sorting of resource files
  *
  * @param $resource_id
  */
 public function rankResourceImages($resource_id)
 {
     if (!$this->modx->getOption('ms2gallery_exact_sorting', null, true, true)) {
         return;
     }
     $q = $this->modx->newQuery('msResourceFile', array('resource_id' => $resource_id, 'parent' => 0));
     $q->select('id');
     $q->sortby('rank ASC, createdon', 'ASC');
     if ($q->prepare() && $q->stmt->execute()) {
         $sql = '';
         $table = $this->modx->getTableName('msResourceFile');
         if ($ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN)) {
             foreach ($ids as $k => $id) {
                 $sql .= "UPDATE {$table} SET `rank` = '{$k}' WHERE (`id` = {$id} OR `parent` = {$id});";
             }
         }
         $sql .= "ALTER TABLE {$table} ORDER BY `rank` ASC;";
         $this->modx->exec($sql);
     }
 }
开发者ID:arkadiy-vl,项目名称:ms2Gallery,代码行数:25,代码来源:ms2gallery.class.php

示例5: COUNT

    disBoard.id,
    disBoard.name,
    disBoard.num_topics,
    (
        SELECT COUNT(`Threads`.`id`) FROM ' . $modx->getTableName('disThread') . ' AS `Threads`
        WHERE `Threads`.`board` = `disBoard`.`id`
    ) AS `real_count`
    FROM ' . $modx->getTableName('disBoard') . ' `disBoard`
    ORDER BY `disBoard`.`map` ASC';
$stmt = $modx->query($sql);
if ($stmt) {
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        if (!empty($row['real_count']) && $row['real_count'] != $row['num_topics']) {
            $modx->log(modX::LOG_LEVEL_ERROR, 'Setting "' . $row['name'] . '" to ' . $row['real_count'] . ' from ' . $row['num_topics']);
            $modx->exec('UPDATE ' . $modx->getTableName('disBoard') . '
                SET `num_topics` = ' . $row['real_count'] . '
                WHERE `id` = ' . $row['id']);
        }
    }
    $stmt->closeCursor();
}
/* fix num_replies */
/* fix total_posts */
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
$modx->log(modX::LOG_LEVEL_INFO, "\nExecution time: {$totalTime}\n");
@session_write_close();
开发者ID:oneismore,项目名称:Discuss,代码行数:31,代码来源:fix.numtopics.php

示例6: COUNT

    (
        SELECT COUNT(`Posts`.`id`) FROM ' . $modx->getTableName('disPost') . ' AS `Posts`
        WHERE `Posts`.`thread` = `disThread`.`id`
    ) AS `real_count`
    FROM ' . $modx->getTableName('disThread') . ' `disThread`
    ORDER BY `disThread`.`id` ASC';
$stmt = $modx->query($sql);
if ($stmt) {
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $row['real_count'] = $row['real_count'] - 1;
        // First post does not count as reply
        //$modx->log(modX::LOG_LEVEL_ERROR,$row['title'] . ' Real: ' . $row['real_count'] . ' Set: '.$row['replies']);
        if (!empty($row['real_count']) && $row['real_count'] != $row['replies']) {
            $modx->log(modX::LOG_LEVEL_ERROR, 'Setting "' . $row['title'] . '" to ' . $row['real_count'] . ' from ' . $row['replies']);
            $modx->exec('UPDATE ' . $modx->getTableName('disThread') . '
                SET `replies` = ' . $row['real_count'] . '
                WHERE `id` = ' . $row['id']);
        }
    }
    $stmt->closeCursor();
}
/* fix total_posts */
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
$modx->log(modX::LOG_LEVEL_INFO, "\nExecution time: {$totalTime}\n");
@session_write_close();
die;
开发者ID:oneismore,项目名称:Discuss,代码行数:31,代码来源:fix.numreplies.php


注:本文中的modX::exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。