git::reset PHP Method

reset() static public method

static public reset ( $pathspec = null, $commitobj = null, $flags = '-q' )
    static function reset($pathspec = null, $commitobj = null, $flags = '-q')
    {
        if ($pathspec) {
            if (is_array($pathspec)) {
                $pathspec = implode(' ', array_map('escapeshellarg', $pathspec));
            } else {
                $pathspec = escapeshellarg($pathspec);
            }
            $pathspec = ' ' . $pathspec;
        }
        $commitargs = '';
        if ($commitobj) {
            $badtype = false;
            if (!is_array($commitobj)) {
                $commitobj = array($commitobj);
            }
            foreach ($commitobj as $c) {
                if (is_object($c)) {
                    if (strtolower(get_class($c)) !== 'GitCommit') {
                        $badtype = true;
                    } else {
                        $commitargs .= ' ' . escapeshellarg($c->id);
                    }
                } elseif (is_string($c)) {
                    $commitargs .= escapeshellarg($c);
                } else {
                    $badtype = true;
                }
                if ($badtype) {
                    throw new InvalidArgumentException('$commitobj argument must be a string, a GitCommit ' . 'object or an array of any of the two mentioned types');
                }
            }
        }
        # clear status cache
        self::$status_cache = null;
        self::exec('reset ' . $flags . ' ' . $commitargs . ' --' . $pathspec);
    }

Usage Example

Example #1
0
 function importChannel(DOMNode $channel, $commit)
 {
     $channel_name = $channel->getElementsByTagName('title')->item(0)->nodeValue;
     $this->report('Importing channel "' . h($channel_name) . '"');
     $fallbackTZOffset = $this->deduceChannelTimezoneOffset($channel);
     $count_posts = 0;
     $count_pages = 0;
     $count_attachments = 0;
     $timer = microtime(1);
     git::reset();
     # rollback any previously prepared commit
     try {
         foreach ($channel->getElementsByTagName('item') as $item) {
             if ($item->nodeType !== XML_ELEMENT_NODE) {
                 continue;
             }
             $obj = $this->importItem($item, $fallbackTZOffset);
             if (!$obj) {
                 continue;
             }
             if ($obj instanceof GBExposedContent) {
                 $this->postProcessExposedContent($obj);
                 $this->report('Importing ' . ($obj instanceof WPPost ? 'post' : 'page') . ' ' . h($obj->name) . ' "' . h($obj->title) . '" by ' . h($obj->author->name) . ' published ' . $obj->published);
                 if ($this->writeExposedContent($obj)) {
                     if ($obj instanceof WPPost) {
                         $count_posts++;
                     } else {
                         $count_pages++;
                     }
                 }
             } elseif ($obj instanceof WPAttachment) {
                 $this->postProcessAttachment($obj);
                 $this->report('Importing attachment ' . h($obj->name) . ' (' . h($obj->wpurl) . ')');
                 if ($this->writeAttachment($obj)) {
                     $count_attachments++;
                 }
             }
             if ($this->debug) {
                 $this->dump($obj);
             }
         }
         $timer = microtime(1) - $timer;
         $count = $count_posts + $count_pages + $count_attachments;
         $this->importedObjectsCount += $count;
         $message = 'Imported ' . counted($count, 'object', 'objects', 'zero', 'one') . ' (' . counted($count_posts, 'post', 'posts', 'zero', 'one') . ', ' . counted($count_pages, 'page', 'pages', 'zero', 'one') . ' and ' . counted($count_attachments, 'attachment', 'attachments', 'zero', 'one') . ')';
         $this->report($message . ' from channel "' . h($channel_name) . '"' . ' in ' . gb_format_duration($timer));
         if ($commit) {
             $this->report('Creating commit...');
             try {
                 git::commit($message . ' from Wordpress blog ' . $channel_name, GBUser::findAdmin()->gitAuthor());
                 $this->report('Committed to git repository');
             } catch (GitError $e) {
                 if (strpos($e->getMessage(), 'nothing added to commit') !== false) {
                     $this->report('Nothing committed because no changes where done');
                 } else {
                     throw $e;
                 }
             }
         }
     } catch (Exception $e) {
         git::reset();
         # rollback prepared commit
         throw $e;
     }
 }
All Usage Examples Of git::reset