Jump to content

IP.Content Database Callbacks


Nuclear General

Recommended Posts

File Name: IP.Content Database Callbacks

File Submitter: Nuclear General

File Submitted: 23 Jul 2012

File Category: Content Management



This Hook Will return much of the granular control and functionality of database callbacks to IP.Content 2.3.x
This is an advanced tool, do NOT come whining at me for your faulty database callback code.
It is Offered without any guarantee of suitability for any specific purpose, even though it is suitable for many.
The startUp method is now optional, and is NOT run in the ACP, while all other methods ARE where appropriate and available.
Included with this download in the ReadMe.html is a full reference of re-enabled usable database callback methods, which span every Content Data Hook present in 2.3.x, and attempt to be compatible with previous callback code/methods.
Be careful not to duplicate code used in data hooks in Content within the database callback methods... they WILL still have effect.



here to download this file

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...

A tested functional example plugin, auto-populates an empty content or title field with the results from a different field for Youtube Videos(url entry is preferable) upon submission.
obviously rename the file, class, and change the field id's.
attachicon.gifdatabase_callback_2.php

Sorry to keep posting in all your topics, but I feel like you have created each add-on specifically for my use. laugh.png

Anyway, does your example account for edits of records? As in it will fetch the youtube url again upon edit of the record into which I am seeking to populate that url?

Link to comment
Share on other sites

  • 1 year later...

I cannot get my preSaveEdit to work, any hints to what I am doing wrong? The preSave works fine. I want to run this before a record is saved after being edited.

<?php
class database_callback_11   // rename this class to match the number of your IP.Content table
{
    public function __construct( $registry )
    {
		
    }
	
    // Run before a edited record is saved, 
	//is passed the submission data, 
	//must return the array it accepts, modified or not.
	public function preSaveEdit($newData) {
	
		if ( $newData['field_64'] > $newData['field_62'] ) {
			
			$oldData = $newData;
			
			$newData['field_61'] =  $oldData['field_63'];
			$newData['field_62'] =  $oldData['field_64'];
			$newData['field_63'] =  $oldData['field_61'];
			$newData['field_64'] =  $oldData['field_62'];
			$newData['field_99'] =  $oldData['field_435'];
			$newData['field_435'] =  $oldData['field_99'];

		}

	return $newData;
    }
	
	// Run before a new record is saved, 
	//is passed the submission data, 
	//must return the array it accepts, modified or not.
	public function preSave($newData) {
	
		if ( $newData['field_64'] > $newData['field_62'] ) {
			
			$oldData = $newData;
			
			$newData['field_61']  =  $oldData['field_63'];
			$newData['field_62']  =  $oldData['field_64'];
			$newData['field_63']  =  $oldData['field_61'];
			$newData['field_64']  =  $oldData['field_62'];
			$newData['field_99']  =  $oldData['field_435'];
			$newData['field_435'] =  $oldData['field_99'];
		}

	return $newData;
    }

	
}
?>
Link to comment
Share on other sites

I cannot get my preSaveEdit to work, any hints to what I am doing wrong? The preSave works fine. I want to run this before a record is saved after being edited.

http://community.invisionpower.com/resources/bugs.html/_/ip-content/datahook-ccspreeditsaveedit-record-r39382

This modification is using the data hooks that were added replacing database callbacks, thus this bug affects that method.

You should be able to just use ipsRegistry::instance()->DB()->update to update the database directly to achieve the desired effect.

Link to comment
Share on other sites

Ok another question, this code isn't running and curious what I am doing wrong.

Thanks in advance

public function postSave($newData) {

		$row = $this->DB->buildAndFetch( array( 'select' => 'field_27', 'from' => 'ccs_custom_database_5', 'where' => "primary_id_field='{$winnerid}'" ) );
		$winner = $row[field_27]; 
		
		
		
		return $newData;
	}

Just trying to do a simple query on the database and it's not going through.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...