• 0

PHP Article Versioning


Question

Okay the problem is as follows. I need to implement article versioning on a site I am building. I need the latest article to also be the one shown on the main page but I also need to be able to view all the old versions of an article.

I have started by always inserting articles into the articles table and never updating them. I have also so made it so the first time I have inserted a new article the version_id of that article becomes equal to the article_id.

I am a bit stuck on what to do now mind. I do understand that every time an insert is done on an existing article I need to make sure that the version_id becomes equal to one.

I am open to any ideas.

Link to comment
https://www.neowin.net/forum/topic/750670-php-article-versioning/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

XML files would be perfect for this. You could allocate one file for all versions of an article and have version numbers and store the latest version number in the row corresponding to the article. That way you will be able to access the most recent version of the article. As you make revisions you can keep adding on new version to the xml file.

  • 0

create a related_to (or something) field with the id of the original article in the article table.

then when doing the select for the listing use the DISTINCT keyword for the related_to field. Just make sure you're sorting by the newest first.

I think that would give you what you want.

Hmm, the more I think about it Original articles would have to have the same value in there related_to and id field.

  • 0

Like +SOOPRcow said, this is actually quite easy to do. You simply do the following:

1. Your articles table should have the following fields included: article_id (Primary Key, Integer), version_number (Integer), version_uid (This is the "related_to" field; it will be the same for all versions of the same article; it simply has to be some unique number or text), and modified_time (DATETIME field)

2. When you create an article, you assign it an article_id, version_number, and version_uid

3. When you edit an article, you create a new article record with a new article_id, you increment the version_number, and then assign the same version_uid as the original article.

  • 0

Just as a caveat: in an ideal relational database system, this would be done with at least 2 tables. One table (articles) would contain the article_id and article_unique_id and other information (such as a BOOLEAN field signaling whether an article is to be displayed or not) while the other table (article_versions) would contain all of the actual article information. The tables would be related to each other by article_unique_id in a one-to-many relationship.

  • 0

This will get the most recent articles by date:

SELECT * FROM articles GROUP BY article_unique_id ORDER BY modified_date DESC

This will get the most recent articles by version:

SELECT * FROM articles GROUP BY article_unique_id ORDER BY version DESC

If that doesn't do what you want, then try this:

SELECT * FROM (SELECT * FROM articles ORDER BY version) GROUP BY article_unique_id

Edited by boogerjones
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I have not even heard of that game. will take a look
    • Chasys Photo 5.41.01 by Razvan Serea Chasys Photo is a suite of image editing applications including a layer-based image editor with adjustment layers, linked layers, timeline and frame-based animation, icon editing, image stacking and comprehensive plug-in support (Chasys Photo Editor), a fast image viewer (Chasys Photo Viewer) and a fast multi-threaded image file converter (Chasys Photo Converter) , with RAW image support in all components. It supports the native file formats of several competitors including Adobe Photoshop, Affinity Photo, ArtWeaver, Corel PhotoPaint, FireAlpaca, GIMP, Krita, Paint.NET, PaintShop Pro and Pixlr, and the whole suite is designed to make effective use of multi-core processors, touch-screens and pen-input devices. Designed under the mantra of “unique, flexible and powerful”, Chasys Photo takes a radically different approach to image editing with the aim of opening up new possibilities for those who dare to be different. Chasys Photo key features: Free-style layering with blending modes Adjustment layers with multiple adjustments per layer Linked layers (a.k.a Linked Smart Objects) Composite, Image List, Frame Animation and Object Animation image modes Animation, both frame-based and object-based (timeline animation) Animation Composer engine Image Stacking for noise reduction, super-resolution, etc. Tablet/Pen-input/Stylus support with pressure control Touch-screen support with gestures including pitch-to-zoom and multi-finger panning Support for the native formats of Adobe Photoshop, Affinity Photo, ArtWeaver, Corel PhotoPaint, FireAlpaca, GIMP, Krita, Paint.NET, PaintShop Pro and Pixlr Support for common formats such as JPEG, animated PNG, animated GIF, TIFF, PICT, WebP, HEIF, DDS, JPEG-2000, JPEG-XR, JPEG-XL, AVI video, etc. Support for the OpenRaster interchange file format and rare formats such as QOI, MNG/JNG and DPX Support for older formats such as PPM/PGM/PBM, PCX/DCX, PCD, TGA, COKE, etc. Comprehensive Camera RAW file support with live adjustment Extensive plug-in support with streamlined SDKs Support for Photoshop Filter Plug-ins (.8BF) Advanced printing and scanning engines PDF document generation Icon and cursor editing, import and export, including Vista-style and Mac-OS icons Screen Capture, including Video Screen Capture with multiple triggering modes Video capture from devices (e.g. TV/Video) Supports multi-core processors, High-DPI displays and Multiple Display setups Integrated File Browser, Bluetooth OBEX and in-built utilities (Calculator, Notepad) Shell integration with thumbnails and conflict detection Unlimited Undo/Redo and Asynchronous Auto-Save, with Just-in-time memory compression to save space Fully re-editable text with advanced styling and effects (TextArt) Full alpha channel through out the workflow with Alpha protection (a.k.a. transparency protection) Multiple language support with user-editable language files and translation assistant (Chasys Photo Language Studio) Anti-aliasing and super-sampling support in tools and paths* Smart-resizing (similar to seam-carving) Best-in-class post-edit heuristics anti-aliasing engine Physical measurement specification with display size detection via EDID Uses the latest CD5 specification with animation and multi-resolution Super-fast internal graphics engine (JpDRAW2) Full UNICODE support in all components Metadata save, restore and scale to imitate vector art Configurable Guides and Grids with Snap-to-Grid Smart-dither to custom palette Asynchronous preview rendering engine Pantone equivalent palettes for PMS 100 to 814-2x Automatic color naming ... and many more! Chasys Photo 5.41.01 changelog: New Features Layered images with multiple pages (Composite/Multi-page) Additional templates to support template-centric workflow New Layer Blend Mode: Inverse Luma Mask Horizon detection in Rotate Transform Cropping option when importing video Orientation options in QR Code Generator plug-in Solved angle ambiguities (CCW versus CW) Internal Improvements Improved graphics engine (JpDRAW2™ v26.05) Improved CD5 codec (v4.10, improved ACSC compression) Improved interpolation when downsizing images Improved motion detection in Video Capture Slightly lower memory usage (RAM is getting expensive!) File Support and Bug Fixes Improved PXZ file support (placeholders, blanks) [bug-fix] Memory leak in flt_JPEG.dll Download: Chasys Photo 5.41.01 | 46.1 MB (Freeware) View: Chasys Photo Home Page | Wikipedia Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • We don't need stars for the word, just use the word "CSAM"
    • If they want to do business in the UK then they can't ignore it. thats why Imgur pulled out of the UK
  • Recent Achievements

    • Very Popular
      Captain_Eric earned a badge
      Very Popular
    • One Month Later
      amusc earned a badge
      One Month Later
    • One Month Later
      DJC50PLUS earned a badge
      One Month Later
    • Week One Done
      DJC50PLUS earned a badge
      Week One Done
    • Proficient
      Eric Biran went up a rank
      Proficient
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      PsYcHoKiLLa
      220
    3. 3
      ATLien_0
      92
    4. 4
      +Edouard
      90
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!