Move entry CRUD operations for entries to WPCOM_Liveblog_Entry #63

Merged
merged 17 commits into from Dec 26, 2012

Conversation

Projects
None yet
2 participants
@nb
Owner

nb commented Dec 20, 2012

Currently, a lot of these operations live in the AJAX endpoints. We should move them to the entry class, where they will have a more logical place and we will be able to reuse them if needed.

See #4.

@nb

This comment has been minimized.

Show comment Hide comment
@nb

nb Dec 20, 2012

Owner

Work in progress.

Owner

nb commented Dec 20, 2012

Work in progress.

nb added some commits Dec 20, 2012

WPCOM_Liveblog_Entry::insert()
It's a static, because it cannot work on an instance.

Since all of the CRUD methods will need to insert a
comment, I added a private insert_comment() method,
too.

Some of the error reporting is crude. For example
we always send a server error, no matter what
broke. Differentiating will be fragile and it
doesn't matter so much.

The update/delete AJAX calls won't work, because
we removed the support until we implement them in
WPCOM_Liveblog_Entry.
Extract Test_Entry::build_entry_args()
Holds default argument values to create an entry and
merges with arbitrary set of values.
Introduce WPCOM_Liveblog_Entry::update()
It's a static because in most of the cases we
don't have an instance when we use it.
Introduce WPCOM_Liveblog_Entry_Query::get_by_id()
Retrieve a single entry by its ID.

get_comments() can't query by ID, so we had to call
get_comment() and then validate if the rest of the
arguments are right.
Use empty string for deleted comment replacement
The content is a string and while a false value would also work, an
empty string makes semantically more sense.
Prefix error code with the entry
We'd better put the more valuable pieces of
information in front of the error code.
Delete the actual comment after replacing it
We had forgotten to delete the comment.
Remove admin-ajax.php hook
We are using only the endpoint URL now.
Consolidate all CRUD AJAX actions
ajax_(insert|update|delete)_entry are now
ajax_crud_entry.

We had to unify the arguments of the corresponding
WPCOM_Liveblog_Entry methods. Now, they all accept
only one argument – $args, which contains the entry_id
if needed.

A lot of deleted code :-)
Get rid of IP and user agent
Comments work perfectly fine without them and we
don't keep this level if logging details for normal
posts either.
@nb

This comment has been minimized.

Show comment Hide comment
@nb

nb Dec 26, 2012

Owner

I think it's done.

Here are the API changes:

  • Three new static methods: insert, update, delete. All of them accept $args, an array with these keys:
    • entry_id – the entry to be affected (no need for it in insert)
    • content – the text of the entry (no need for it in delete)
    • post_id
    • user – the user object for the author of the change
      All of them return the newly inserted entry, which replaces the previous one. Or a WP_Error instance.
  • A few new instance accessor methods:
    • get_post_id()
    • get_content()
Owner

nb commented Dec 26, 2012

I think it's done.

Here are the API changes:

  • Three new static methods: insert, update, delete. All of them accept $args, an array with these keys:
    • entry_id – the entry to be affected (no need for it in insert)
    • content – the text of the entry (no need for it in delete)
    • post_id
    • user – the user object for the author of the change
      All of them return the newly inserted entry, which replaces the previous one. Or a WP_Error instance.
  • A few new instance accessor methods:
    • get_post_id()
    • get_content()

nb added a commit that referenced this pull request Dec 26, 2012

Merge pull request #63 from Automattic/refactoring/move-crud-to-entry
Move entry CRUD operations for entries to WPCOM_Liveblog_Entry

Fixes #4.

@nb nb merged commit 75093ff into master Dec 26, 2012

@nb nb deleted the refactoring/move-crud-to-entry branch Dec 26, 2012

@nitinthewiz

This comment has been minimized.

Show comment Hide comment
@nitinthewiz

nitinthewiz Jan 10, 2013

Would it be possible to get some examples or documentation on these new methods?

Would it be possible to get some examples or documentation on these new methods?

@nb

This comment has been minimized.

Show comment Hide comment
@nb

nb Jan 14, 2013

Owner

@nitinthewiz The code should be simple enough to understand :-)

If I remember correctly your use-case was to insert a new entry, right? Then, this should be enough:

<?php
$new_entry = WPCOM_Liveblog_Entry::insert( array(
    'post_id' => $post_id,
    'content' => 'He kicked the ball!',
    'user' => wp_get_current_user(),
) );
Owner

nb commented Jan 14, 2013

@nitinthewiz The code should be simple enough to understand :-)

If I remember correctly your use-case was to insert a new entry, right? Then, this should be enough:

<?php
$new_entry = WPCOM_Liveblog_Entry::insert( array(
    'post_id' => $post_id,
    'content' => 'He kicked the ball!',
    'user' => wp_get_current_user(),
) );
@nitinthewiz

This comment has been minimized.

Show comment Hide comment
@nitinthewiz

nitinthewiz Jan 14, 2013

Hey thanks! That helped me make a small script I can use to post to my liveblog... Only thing is, I have to open the exact path -> /wp-content/plugins/liveblog/quickpost.php instead of a page on my blog... Haven't figured that out yet... :)

Hey thanks! That helped me make a small script I can use to post to my liveblog... Only thing is, I have to open the exact path -> /wp-content/plugins/liveblog/quickpost.php instead of a page on my blog... Haven't figured that out yet... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment