Esempio n. 1
0
    protected function processDBData()
    {
        parent::processDBData();
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        // delete attached files using their dataobjects to remove the actual
        // files
        $sql = sprintf('select * from BlorgFile
			inner join BlorgPost on BlorgPost.id = BlorgFile.post
			where BlorgPost.instance %s %s and BlorgFile.post in (%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list);
        $files = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgFileWrapper'));
        foreach ($files as $file) {
            $file->setFileBase('../');
            $file->delete();
        }
        // delete the posts
        $sql = sprintf('delete from BlorgPost
			where instance %s %s and id in (%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list);
        $num = SwatDB::exec($this->app->db, $sql);
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNS('posts');
        }
        $message = new SwatMessage(sprintf(Blorg::ngettext('One post has been deleted.', '%s posts have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
Esempio n. 2
0
    public function processActions(SwatTableView $view, SwatActions $actions)
    {
        $num = count($view->getSelection());
        $message = null;
        $items = SwatDB::implodeSelection($this->app->db, $view->getSelection(), 'integer');
        switch ($actions->selected->id) {
            case 'delete':
                $this->app->replacePage($this->getComponentName() . '/Delete');
                $this->app->getPage()->setItems($view->getSelection());
                break;
            case 'enable':
                $instance_id = $this->app->getInstanceId();
                $num = SwatDB::exec($this->app->db, sprintf('update BlorgAuthor set visible = %s
				where instance %s %s and id in (%s)', $this->app->db->quote(true, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $items));
                if ($num > 0 && isset($this->app->memcache)) {
                    $this->app->memcache->flushNs('authors');
                }
                $message = new SwatMessage(sprintf(Blorg::ngettext('One author has been shown on site.', '%s authors have been shown on site.', $num), SwatString::numberFormat($num)));
                break;
            case 'disable':
                $instance_id = $this->app->getInstanceId();
                $num = SwatDB::exec($this->app->db, sprintf('update BlorgAuthor set visible = %s
				where instance %s %s and id in (%s)', $this->app->db->quote(false, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $items));
                if ($num > 0 && isset($this->app->memcache)) {
                    $this->app->memcache->flushNs('authors');
                }
                $message = new SwatMessage(sprintf(Blorg::ngettext('One author has been hidden on site.', '%s authors have been hidden on site.', $num), SwatString::numberFormat($num)));
                break;
        }
        if ($message !== null) {
            $this->app->messages->add($message);
        }
    }
Esempio n. 3
0
 public function finalize()
 {
     $base_sql = 'update Article set parent = %s where id = %s';
     foreach ($this->table->parents as $id => $parent) {
         $sql = sprintf($base_sql, $this->table->process->dst_db->quote($parent, 'integer'), $this->table->process->dst_db->quote($id, 'integer'));
         SwatDB::exec($this->table->process->dst_db, $sql);
     }
 }
    protected function addToSearchQueue(PinholePhoto $photo)
    {
        $type = NateGoSearch::getDocumentType($this->app->db, 'photo');
        $sql = sprintf('delete from NateGoSearchQueue
			where document_id = %s and document_type = %s', $this->app->db->quote($photo->id, 'integer'), $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        $sql = sprintf('insert into NateGoSearchQueue
			(document_id, document_type) values (%s, %s)', $this->app->db->quote($photo->id, 'integer'), $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
    }
Esempio n. 5
0
    /**
     * Marks a file as not attached
     *
     * @param integer $file_id the id of the file to mark as not attached.
     *
     * @return boolean true.
     */
    public function detach($file_id)
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('update BlorgFile set visible = %s
			where instance %s %s and id = %s', $this->app->db->quote(false, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote($file_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        if ($num > 0 && isset($this->app->memcache)) {
            $this->app->memcache->flushNS('posts');
        }
        return true;
    }
Esempio n. 6
0
    protected function saveIndex($id, $index)
    {
        SwatDB::updateColumn($this->app->db, 'BlorgAuthor', 'integer:displayorder', $index, 'integer:id', array($id));
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('update BlorgAuthor set displayorder = %s
			where id = %s and instance %s %s', $this->app->db->quote($index, 'integer'), $this->app->db->quote($id, 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNs('authors');
        }
    }
Esempio n. 7
0
 protected function processDBData()
 {
     parent::processDBData();
     $sql = 'delete from CMEFrontMatter where id in (%s);';
     $item_list = $this->getItemList('integer');
     $sql = sprintf($sql, $item_list);
     $num = SwatDB::exec($this->app->db, $sql);
     $locale = SwatI18NLocale::get();
     $message = new SwatMessage(sprintf(CME::ngettext('One CME front matter has been deleted.', '%s CME front matters have been deleted.', $num), $locale->formatNumber($num)));
     $this->app->messages->add($message);
 }
Esempio n. 8
0
 protected function processDBData()
 {
     parent::processDBData();
     $sql = 'delete from Block where id in (%s)';
     $item_list = $this->getItemList('integer');
     $sql = sprintf($sql, $item_list);
     $num = SwatDB::exec($this->app->db, $sql);
     if ($num > 0) {
         $this->app->messages->add(new SwatMessage(Building::_('Content has been deleted.')));
     }
 }
Esempio n. 9
0
    protected function processDBData()
    {
        parent::processDBData();
        $instance_id = $this->app->getInstanceId();
        $sql = 'delete from PinholePhotographer where id in (%s)
			and instance %s %s';
        $item_list = $this->getItemList('integer');
        $sql = sprintf($sql, $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        $message = new SwatMessage(sprintf(Pinhole::ngettext('One photographer has been deleted.', '%s photographers have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
Esempio n. 10
0
    protected function addToSearchQueue()
    {
        $type = NateGoSearch::getDocumentType($this->app->db, 'comment');
        if ($type === null) {
            return;
        }
        $sql = sprintf('delete from NateGoSearchQueue
			where document_id = %s and document_type = %s', $this->app->db->quote($this->comment->id, 'integer'), $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        $sql = sprintf('insert into NateGoSearchQueue
			(document_id, document_type) values (%s, %s)', $this->app->db->quote($this->comment->id, 'integer'), $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
    }
Esempio n. 11
0
 protected function processDBData()
 {
     parent::processDBData();
     $item_list = $this->getItemList('integer');
     $sql = sprintf('delete from BlorgTag where id in (%s)', $item_list);
     $num = SwatDB::exec($this->app->db, $sql);
     if (isset($this->app->memcache)) {
         $this->app->memcache->flushNs('tags');
         $this->app->memcache->flushNs('posts');
     }
     $message = new SwatMessage(sprintf(Blorg::ngettext('One tag has been deleted.', '%s tags have been deleted.', $num), SwatString::numberFormat($num)));
     $this->app->messages->add($message);
 }
Esempio n. 12
0
    protected function processDBData()
    {
        AdminDBDelete::processDBData();
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select parent from Article
			where id = %s and instance %s %s', $this->app->db->quote($this->getFirstItem(), 'integer'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $this->parent_id = SwatDB::queryOne($this->app->db, $sql);
        $item_list = $this->getItemList('integer');
        $sql = sprintf('delete from Article
			where id in (%s) and instance %s %s', $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        $message = new SwatMessage(sprintf(Site::ngettext('One article has been deleted.', '%s articles have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
Esempio n. 13
0
    public function processActions(SwatTableView $view, SwatActions $actions)
    {
        $message = null;
        $items = SwatDB::implodeSelection($this->app->db, $view->getSelection(), 'integer');
        switch ($actions->selected->id) {
            case 'delete':
                $this->app->replacePage($this->getComponentName() . '/Delete');
                $this->app->getPage()->setItems($view->getSelection());
                break;
            case 'enable':
                $this->publishPosts($view->getSelection());
                break;
            case 'disable':
                $instance_id = $this->app->getInstanceId();
                $num = SwatDB::exec($this->app->db, sprintf('update BlorgPost set enabled = %s
				where instance %s %s and id in (%s)', $this->app->db->quote(false, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $items));
                if ($num > 0 && isset($this->app->memcache)) {
                    $this->app->memcache->flushNs('posts');
                }
                $message = new SwatMessage(sprintf(Blorg::ngettext('One post has been hidden on site.', '%s posts have been hidden on site.', $num), SwatString::numberFormat($num)));
                break;
            case 'tags_action':
                $tag_array = $this->ui->getWidget('tags')->getSelectedTagArray();
                if (count($tag_array) > 0) {
                    $posts = $this->getPostsFromSelection($view->getSelection());
                    foreach ($posts as $post) {
                        $post->addTagsByShortname($tag_array);
                    }
                    if (isset($this->app->memcache)) {
                        $this->app->memcache->flushNs('posts');
                        $this->app->memcache->flushNs('tags');
                    }
                    $num = count($view->getSelection());
                    $num_tags = count($tag_array);
                    if ($num_tags === 1) {
                        $tag = reset($tag_array);
                        $message = new SwatMessage(sprintf(Blorg::ngettext('The tag “%s” has been added to one post.', 'The tag “%s” has been added to %s posts.', $num), SwatString::minimizeEntities($tag), SwatString::numberFormat($num)));
                    } else {
                        $message = new SwatMessage(sprintf(Blorg::ngettext('%s tags have been added to one post.', '%s tags have been added to %s posts.', $num), SwatString::numberFormat($num_tags), SwatString::numberFormat($num)));
                    }
                    // clear selected tags
                    $this->ui->getWidget('tags')->setSelectedTagArray(array());
                }
                break;
        }
        if ($message !== null) {
            $this->app->messages->add($message);
        }
    }
Esempio n. 14
0
    protected function processDBData()
    {
        parent::processDBData();
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('delete from BlorgAuthor where id in (%s)
			and instance %s %s', $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNs('authors');
            $this->app->memcache->flushNs('posts');
        }
        $message = new SwatMessage(sprintf(Blorg::ngettext('One author has been deleted.', '%s authors have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
Esempio n. 15
0
 protected function processDBData()
 {
     parent::processDBData();
     $sql = 'delete from PinholeTag where instance %s %s';
     $item_list = $this->getItemList('integer');
     $instance_id = $this->app->getInstanceId();
     $sql = sprintf($sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
     if (!$this->extended_selected) {
         $sql .= sprintf(' and id in (%s)', $item_list);
     }
     $num = SwatDB::exec($this->app->db, $sql);
     if (isset($this->app->memcache)) {
         $this->app->memcache->flushNs('photos');
     }
     $message = new SwatMessage(sprintf(Pinhole::ngettext('One tag has been deleted.', '%s tags have been deleted.', $num), SwatString::numberFormat($num)));
     $this->app->messages->add($message);
 }
Esempio n. 16
0
    /**
     * Update a photo
     *
     * @param array $photo_ids The photo its to update
     * @param float $latitude Latitude
     * @param float $longitude Longitude
     * @param integer $zoom_level Zoom level for storing as a preference
     *
     * @return array The photo ids that were updated.
     */
    public function setPhotoGpsData(array $photo_ids, $latitude, $longitude, $zoom_level)
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('update PinholePhoto set
			gps_latitude = %s, gps_longitude = %s
			where PinholePhoto.id in (select PinholePhoto.id from PinholePhoto
				inner join ImageSet on ImageSet.id = PinholePhoto.image_set
				where ImageSet.instance %s %s and PinholePhoto.id in (%s))', $this->app->db->quote($latitude, 'float'), $this->app->db->quote($longitude, 'float'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->implodeArray($photo_ids, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        // save preferences
        $this->app->config->pinhole->map_last_latitude = $latitude;
        $this->app->config->pinhole->map_last_longitude = $longitude;
        $this->app->config->pinhole->map_last_zoom_level = $zoom_level;
        $this->app->config->save(array('pinhole.map_last_latitude', 'pinhole.map_last_longitude', 'pinhole.map_last_zoom_level'));
        // clear cache
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNs('photos');
        }
        return $photo_ids;
    }
    /**
     * Deletes this object from the database
     */
    protected function deleteInternal()
    {
        if ($this->instance === null) {
            parent::deleteInternal();
        }
        if ($this->table === null || $this->id_field === null) {
            return;
        }
        $id_field = new SwatDBField($this->id_field, 'integer');
        if (!property_exists($this, $id_field->name)) {
            return;
        }
        $id_ref = $id_field->name;
        $id = $this->{$id_ref};
        $instance_id = $this->instance === null ? null : $this->instance->id;
        if ($id !== null) {
            $sql = sprintf('delete from %s
				where %s = %s and instance %s %s', $this->table, $id_field->name, $id, SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
            SwatDB::exec($this->db, $sql);
        }
    }
Esempio n. 18
0
    protected function addToSearchQueue($ids)
    {
        // this is automatically wrapped in a transaction because it is
        // called in saveDBData()
        $type = NateGoSearch::getDocumentType($this->app->db, 'post');
        if ($type === null) {
            return;
        }
        $sql = sprintf('delete from NateGoSearchQueue
			where
				document_id in
					(select distinct BlorgComment.post from BlorgComment
						where BlorgComment.id in (%s))
				and document_type = %s', $ids, $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        $sql = sprintf('insert into NateGoSearchQueue
			(document_id, document_type)
			select distinct BlorgComment.post, %s from
				BlorgComment where BlorgComment.id in (%s)', $this->app->db->quote($type, 'integer'), $ids);
        SwatDB::exec($this->app->db, $sql);
    }
Esempio n. 19
0
    protected function processDBData()
    {
        parent::processDBData();
        $tags = $this->ui->getWidget('dst_tag')->getSelectedTagArray();
        $dst_tag = new PinholeTagDataObject();
        $dst_tag->setDatabase($this->app->db);
        $dst_tag->loadByName(key($tags), $this->app->getInstance());
        // delete intersection tagged photos
        $sql = sprintf('delete from pinholephototagbinding where tag = %s
			and photo in (select photo from pinholephototagbinding
				where pinholephototagbinding.tag = %s)', $this->app->db->quote($this->source_tag->id, 'integer'), $this->app->db->quote($dst_tag->id, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        // add source_tagged photos to dst_tagged photos
        $sql = sprintf('insert into pinholephototagbinding (photo, tag)
			select pinholephototagbinding.photo, %s
			from pinholephototagbinding where tag = %s', $this->app->db->quote($dst_tag->id, 'integer'), $this->app->db->quote($this->source_tag->id, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        // delete source_tag
        $this->source_tag->delete();
        $this->app->messages->add(new SwatMessage(sprintf(Pinhole::_('“%s” has been merged into “%s”'), $this->source_tag->title, $dst_tag->title)));
    }
Esempio n. 20
0
 public function create($db)
 {
     echo "Creating object ", $this->name, "\n";
     echo "\tfrom ", $this->filename, "\n";
     SwatDB::exec($db, $this->sql);
 }
Esempio n. 21
0
 protected function processDBData()
 {
     parent::processDBData();
     $locale = SwatI18NLocale::get();
     $relocate = true;
     $message = null;
     $delete_count = 0;
     $error_count = 0;
     $newsletters = $this->getNewsletters();
     foreach ($newsletters as $newsletter) {
         // only allow deleting unsent newsletters. There is nothing
         // technically stopping us from deleting ones that have been sent,
         // but do this for the sake of stats until deleting sent newsletters
         // is required.
         if ($newsletter->isSent() == false) {
             $list = $this->getList($newsletter);
             $campaign_type = $newsletter->instance instanceof SiteInstance ? $newsletter->instance->shortname : null;
             $campaign = $newsletter->getCampaign($this->app, $campaign_type);
             $transaction = new SwatDBTransaction($this->app->db);
             try {
                 // If not a draft, remove the resources. Don't delete draft
                 // newsletter resources as they are shared across all
                 // drafts.
                 if ($newsletter->isScheduled()) {
                     DeliveranceCampaign::removeResources($this->app, $campaign);
                 }
                 $list->deleteCampaign($campaign);
                 $sql = 'delete from Newsletter where id = %s';
                 $sql = sprintf($sql, $this->app->db->quote($newsletter->id, 'integer'));
                 $delete_count += SwatDB::exec($this->app->db, $sql);
                 $transaction->commit();
             } catch (DeliveranceAPIConnectionException $e) {
                 $transaction->rollback();
                 $e->processAndContinue();
                 $error_count++;
                 $relocate = false;
             } catch (Exception $e) {
                 $transaction->rollback();
                 $e = new DeliveranceException($e);
                 $e->processAndContinue();
                 $error_count++;
                 $relocate = false;
             }
         }
     }
     if ($delete_count > 0) {
         $message = new SwatMessage(sprintf(Deliverance::ngettext('One newsletter has been deleted.', '%s newsletters have been deleted.', $delete_count), $locale->formatNumber($delete_count)), 'notice');
         $this->app->messages->add($message);
     }
     if ($error_count > 0) {
         $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email service ' . 'provider.'), 'error');
         $message->content_type = 'text/xml';
         $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::ngettext('One newsletter has not been deleted.', '%s newsletters have not been deleted.', $error_count), $locale->formatNumber($error_count)), Deliverance::ngettext('Connection issues are typically short-lived and ' . 'attempting to delete the newsletter again after a ' . 'delay  will usually be successful.', 'Connection issues are typically short-lived and ' . 'attempting to delete the newsletters again after a ' . 'delay will usually be successful.', $error_count));
     }
     return $relocate;
 }
Esempio n. 22
0
    protected function indexComments()
    {
        $type_shortname = 'comment';
        $spell_checker = new NateGoSearchPSpellSpellChecker('en_US', '', '', $this->getCustomWordList());
        $comment_indexer = new NateGoSearchIndexer($type_shortname, $this->db);
        $comment_indexer->setSpellChecker($spell_checker);
        $comment_indexer->addTerm(new NateGoSearchTerm('fullname', 30));
        $comment_indexer->addTerm(new NateGoSearchTerm('email', 20));
        $comment_indexer->addTerm(new NateGoSearchTerm('bodytext', 1));
        $comment_indexer->setMaximumWordLength(32);
        $comment_indexer->addUnindexedWords(NateGoSearchIndexer::getDefaultUnindexedWords());
        $type = NateGoSearch::getDocumentType($this->db, $type_shortname);
        $sql = sprintf('select BlorgComment.*
			from BlorgComment
				inner join NateGoSearchQueue
					on BlorgComment.id = NateGoSearchQueue.document_id
					and NateGoSearchQueue.document_type = %s
			order by BlorgComment.id', $this->db->quote($type, 'integer'));
        $this->debug(Blorg::_('Indexing comments... ') . '   ');
        $comments = SwatDB::query($this->db, $sql, SwatDBClassMap::get('BlorgCommentWrapper'));
        $total = count($comments);
        $count = 0;
        foreach ($comments as $comment) {
            $ds = new SwatDetailsStore($comment);
            if ($count % 10 == 0) {
                $comment_indexer->commit();
                $this->debug(str_repeat(chr(8), 3));
                $this->debug(sprintf('%2d%%', $count / $total * 100));
            }
            $document = new NateGoSearchDocument($ds, 'id');
            $comment_indexer->index($document);
            $count++;
        }
        $this->debug(str_repeat(chr(8), 3) . Blorg::_('done') . "\n");
        $comment_indexer->commit();
        unset($comment_indexer);
        $sql = sprintf('delete from NateGoSearchQueue where document_type = %s', $this->db->quote($type, 'integer'));
        SwatDB::exec($this->db, $sql);
    }
Esempio n. 23
0
    protected function processInternal()
    {
        $form = $this->ui->getWidget('index_form');
        if ($form->isProcessed()) {
            $view = $form->getFirstDescendant('SwatView');
            $renderer = $view->getColumn('value_column')->getFirstRenderer();
            $modified = false;
            foreach ($this->getMetaData() as $data) {
                $widget = $renderer->getWidget($data->id);
                if ($widget->value != $data->value) {
                    $modified = true;
                    if ($data->value === null) {
                        $sql = sprintf('insert into PinholePhotoMetaDataBinding
							(value, photo, meta_data) values (%s, %s, %s)', $this->app->db->quote($widget->value, 'text'), $this->app->db->quote($this->photo->id, 'integer'), $this->app->db->quote($data->id, 'integer'));
                    } elseif ($widget->value === null) {
                        $sql = sprintf('delete from PinholePhotoMetaDataBinding
							where photo = %s and meta_data = %s', $this->app->db->quote($widget->value, 'text'), $this->app->db->quote($this->photo->id, 'integer'), $this->app->db->quote($data->id, 'integer'));
                    } else {
                        $sql = sprintf('update PinholePhotoMetaDataBinding set
							value = %s where photo = %s and meta_data = %s', $this->app->db->quote($widget->value, 'text'), $this->app->db->quote($this->photo->id, 'integer'), $this->app->db->quote($data->id, 'integer'));
                    }
                    SwatDB::exec($this->app->db, $sql);
                }
            }
            if ($modified) {
                $this->app->messages->add(new SwatMessage(Pinhole::_('Metadata Updated')));
                if (isset($this->app->memcache)) {
                    $this->app->memcache->flushNs('photos');
                }
            }
        }
    }
Esempio n. 24
0
    /**
     * Applies this tag to a photo
     *
     * Any unsaved changes to the tag and photo are saved before this tag is
     * applied to the photo.
     *
     * @param PinholePhoto $photo the photo this tag is to be applied to.
     */
    public function applyToPhoto(PinholePhoto $photo)
    {
        $transaction = new SwatDBTransaction($this->db);
        try {
            // save photo and tag
            $photo->save();
            $this->save();
            // save binding
            $sql = sprintf('insert into PhotoPhotoTagBinding (photo, tag)
				values (%s, %s)', $this->db->quote($photo->id, 'integer'), $this->db->quote($this->id, 'integer'));
            SwatDB::exec($this->db, $sql);
            $transaction->commit();
        } catch (Exception $e) {
            $transaction->rollback();
            throw $e;
        }
        $this->photos->add($photo);
    }
Esempio n. 25
0
    public function setTagsByShortname(array $tag_names)
    {
        $this->checkDB();
        $this->db->loadModule('Datatype');
        $return = array();
        $shortnames = array_keys($tag_names);
        $instance_id = $this->getInternalValue('instance');
        // delete all tags not in the selected tags
        $sql = sprintf('delete from BlorgPostTagBinding where post = %s and
			tag not in (select id from BlorgTag where shortname in (%s) and
				instance %s %s)', $this->db->quote($this->id, 'integer'), $this->db->datatype->implodeArray($shortnames, 'text'), SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
        $num = SwatDB::exec($this->db, $sql);
        $return['removed'] = $num;
        // add tags
        return array_merge($this->addTagsByShortname($tag_names), $return);
    }
    protected function indexPhotos()
    {
        $spell_checker = new NateGoSearchPSpellSpellChecker('en_US', '', '', $this->getCustomWordList());
        $photo_indexer = new NateGoSearchIndexer('photo', $this->db);
        $photo_indexer->setSpellChecker($spell_checker);
        $photo_indexer->addTerm(new NateGoSearchTerm('title', 5));
        $photo_indexer->addTerm(new NateGoSearchTerm('tags', 2));
        $photo_indexer->addTerm(new NateGoSearchTerm('description'));
        $photo_indexer->setMaximumWordLength(32);
        $photo_indexer->addUnindexedWords(NateGoSearchIndexer::getDefaultUnindexedWords());
        $type = NateGoSearch::getDocumentType($this->db, 'photo');
        $sql = sprintf('select PinholePhoto.title, PinholePhoto.id,
				PinholePhoto.description, PinholePhoto.image_set
			from PinholePhoto
				inner join NateGoSearchQueue
					on PinholePhoto.id = NateGoSearchQueue.document_id
					and NateGoSearchQueue.document_type = %s
			order by PinholePhoto.id', $this->db->quote($type, 'integer'));
        $this->debug(Pinhole::_('Indexing photos ... ') . '   ');
        $photos = SwatDB::query($this->db, $sql, SwatDBClassMap::get('PinholePhotoWrapper'));
        $total = count($photos);
        $count = 0;
        $current_photo_id = null;
        foreach ($photos as $photo) {
            $ds = new SwatDetailsStore($photo);
            $ds->title = $photo->getTitle();
            $tags = '';
            foreach ($photo->tags as $tag) {
                $tags .= ' ' . $tag->title . ' ' . $tag->name;
            }
            $ds->tags = $tags;
            if ($count % 10 == 0) {
                $photo_indexer->commit();
                $this->debug(str_repeat(chr(8), 3));
                $this->debug(sprintf('%2d%%', $count / $total * 100));
            }
            $document = new NateGoSearchDocument($ds, 'id');
            $photo_indexer->index($document);
            $current_photo_id = $photo->id;
            $count++;
            $sql = sprintf('delete from NateGoSearchQueue where
				document_type = %s and document_id = %s', $this->db->quote($type, 'integer'), $this->db->quote($photo->id, 'integer'));
            SwatDB::exec($this->db, $sql);
        }
        if (count($photos) > 0 && isset($this->memcache)) {
            $this->memcache->flushNs('photos');
        }
        $this->debug(str_repeat(chr(8), 3) . Pinhole::_('done') . "\n");
        $photo_indexer->commit();
        unset($photo_indexer);
    }
Esempio n. 27
0
 protected function clearDestinationTable()
 {
     $sql = sprintf('delete from %s where instance = %s', $this->dst_table, $this->process->dst_db->quote($this->process->instance, 'integer'));
     return SwatDB::exec($this->process->dst_db, $sql);
 }
Esempio n. 28
0
    protected function addToSearchQueue()
    {
        // this is automatically wrapped in a transaction because it is
        // called in saveDBData()
        $type = NateGoSearch::getDocumentType($this->app->db, 'post');
        if ($type === null) {
            return;
        }
        $sql = sprintf('delete from NateGoSearchQueue
			where document_id = %s and document_type = %s', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
        $sql = sprintf('insert into NateGoSearchQueue
			(document_id, document_type) values (%s, %s)', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote($type, 'integer'));
        SwatDB::exec($this->app->db, $sql);
    }
Esempio n. 29
0
    protected function addDateParts()
    {
        $item_list = $this->getItemList('integer');
        $date_parts = array('year', 'month', 'day', 'hour', 'minute', 'second');
        $date_parts_sql = 'photo_date = photo_date';
        foreach ($date_parts as $part) {
            $value = $this->ui->getWidget('time_' . $part)->value;
            if ($value !== null) {
                $date_parts_sql .= sprintf('+ interval %s', $this->app->db->quote($value . ' ' . $part, 'text'));
            }
        }
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('update PinholePhoto set %s
			where PinholePhoto.image_set in (
				select id from ImageSet where instance %s %s)', $date_parts_sql, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        // note the only page with an extended-selection that accesses this
        // is the pending photos page - so enforce status here.
        if ($this->extended_selected) {
            $sql .= sprintf(' and PinholePhoto.status = %s', $this->app->db->quote(PinholePhoto::STATUS_PENDING, 'integer'));
        } else {
            $sql .= sprintf(' and PinholePhoto.id in (%s)', $item_list);
        }
        return SwatDB::exec($this->app->db, $sql);
    }
Esempio n. 30
0
    protected function saveProviderBindingTable()
    {
        $front_matter = $this->getObject();
        $providers = $this->ui->getWidget('providers')->values;
        $delete_sql = sprintf('delete from CMEFrontMatterProviderBinding
			where front_matter = %s', $this->app->db->quote($front_matter->id, 'integer'));
        SwatDB::exec($this->app->db, $delete_sql);
        $insert_sql = sprintf('insert into CMEFrontMatterProviderBinding
			(front_matter, provider)
			select %s, id from CMEProvider where id in (%s)', $this->app->db->quote($front_matter->id, 'integer'), $this->app->db->datatype->implodeArray($providers, 'integer'));
        SwatDB::exec($this->app->db, $insert_sql);
    }