2015-08-24 20:22:07 +00:00
< ? php
/*----------------------------------------------------------------------------------| www . vdm . io |----/
Vast Development Method
/-------------------------------------------------------------------------------------------------------/
2017-04-08 18:35:55 +00:00
@ version 2.0 . 0
2017-08-21 12:17:01 +00:00
@ build 21 st August , 2017
2017-04-08 18:35:55 +00:00
@ created 18 th October , 2016
2015-08-24 20:22:07 +00:00
@ package Demo
@ subpackage script . php
@ author Llewellyn van der Merwe < https :// www . vdm . io />
@ copyright Copyright ( C ) 2015. All Rights Reserved
@ license GNU / GPL Version 2 or later - http :// www . gnu . org / licenses / gpl - 2.0 . html
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
( _ _ )( _ )( _ )( \ / )( ) / __\ / __ )( _ )( \ / )( _ \ ( _ )( \ ( )( ___ )( \ ( )( _ _ )
.- _ )( )( _ )( )( _ )( ) ( )( __ / ( __ ) \ ( ( __ )( _ )( ) ( ) ___ / )( _ )( ) ( ) __ ) ) ( )(
\____ ) ( _____ )( _____ )( _ / \ / \_ )( ____ )( __ )( __ ) \___ )( _____ )( _ / \ / \_ )( __ ) ( _____ )( _ ) \_ )( ____ )( _ ) \_ ) ( __ )
/------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
JHTML :: _ ( 'behavior.modal' );
jimport ( 'joomla.installer.installer' );
jimport ( 'joomla.installer.helper' );
/**
* Script File of Demo Component
*/
class com_demoInstallerScript
{
/**
* method to install the component
*
* @ return void
*/
function install ( $parent )
{
}
/**
* method to uninstall the component
*
* @ return void
*/
function uninstall ( $parent )
{
// Get Application object
$app = JFactory :: getApplication ();
// Get The Database object
$db = JFactory :: getDbo ();
// Create a new query object.
$query = $db -> getQuery ( true );
// Select id from content type table
$query -> select ( $db -> quoteName ( 'type_id' ));
$query -> from ( $db -> quoteName ( '#__content_types' ));
// Where Look alias is found
$query -> where ( $db -> quoteName ( 'type_alias' ) . ' = ' . $db -> quote ( 'com_demo.look' ) );
$db -> setQuery ( $query );
// Execute query to see if alias is found
$db -> execute ();
$look_found = $db -> getNumRows ();
// Now check if there were any rows
if ( $look_found )
{
// Since there are load the needed look type ids
$look_ids = $db -> loadColumn ();
// Remove Look from the content type table
$look_condition = array ( $db -> quoteName ( 'type_alias' ) . ' = ' . $db -> quote ( 'com_demo.look' ) );
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> delete ( $db -> quoteName ( '#__content_types' ));
$query -> where ( $look_condition );
$db -> setQuery ( $query );
// Execute the query to remove Look items
$look_done = $db -> execute ();
if ( $look_done );
{
// If succesfully remove Look add queued success message.
$app -> enqueueMessage ( JText :: _ ( 'The (com_demo.look) type alias was removed from the <b>#__content_type</b> table' ));
}
// Remove Look items from the contentitem tag map table
$look_condition = array ( $db -> quoteName ( 'type_alias' ) . ' = ' . $db -> quote ( 'com_demo.look' ) );
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> delete ( $db -> quoteName ( '#__contentitem_tag_map' ));
$query -> where ( $look_condition );
$db -> setQuery ( $query );
// Execute the query to remove Look items
$look_done = $db -> execute ();
if ( $look_done );
{
// If succesfully remove Look add queued success message.
$app -> enqueueMessage ( JText :: _ ( 'The (com_demo.look) type alias was removed from the <b>#__contentitem_tag_map</b> table' ));
}
// Remove Look items from the ucm content table
$look_condition = array ( $db -> quoteName ( 'core_type_alias' ) . ' = ' . $db -> quote ( 'com_demo.look' ) );
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> delete ( $db -> quoteName ( '#__ucm_content' ));
$query -> where ( $look_condition );
$db -> setQuery ( $query );
// Execute the query to remove Look items
$look_done = $db -> execute ();
if ( $look_done );
{
// If succesfully remove Look add queued success message.
$app -> enqueueMessage ( JText :: _ ( 'The (com_demo.look) type alias was removed from the <b>#__ucm_content</b> table' ));
}
// Make sure that all the Look items are cleared from DB
foreach ( $look_ids as $look_id )
{
// Remove Look items from the ucm base table
$look_condition = array ( $db -> quoteName ( 'ucm_type_id' ) . ' = ' . $look_id );
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> delete ( $db -> quoteName ( '#__ucm_base' ));
$query -> where ( $look_condition );
$db -> setQuery ( $query );
// Execute the query to remove Look items
$db -> execute ();
// Remove Look items from the ucm history table
$look_condition = array ( $db -> quoteName ( 'ucm_type_id' ) . ' = ' . $look_id );
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> delete ( $db -> quoteName ( '#__ucm_history' ));
$query -> where ( $look_condition );
$db -> setQuery ( $query );
// Execute the query to remove Look items
$db -> execute ();
}
}
// If All related items was removed queued success message.
$app -> enqueueMessage ( JText :: _ ( 'All related items was removed from the <b>#__ucm_base</b> table' ));
$app -> enqueueMessage ( JText :: _ ( 'All related items was removed from the <b>#__ucm_history</b> table' ));
// Remove demo assets from the assets table
$demo_condition = array ( $db -> quoteName ( 'name' ) . ' LIKE ' . $db -> quote ( 'com_demo%' ) );
// Create a new query object.
$query = $db -> getQuery ( true );
$query -> delete ( $db -> quoteName ( '#__assets' ));
$query -> where ( $demo_condition );
$db -> setQuery ( $query );
2017-04-08 18:35:55 +00:00
$look_done = $db -> execute ();
if ( $look_done );
2015-08-24 20:22:07 +00:00
{
// If succesfully remove demo add queued success message.
$app -> enqueueMessage ( JText :: _ ( 'All related items was removed from the <b>#__assets</b> table' ));
}
// little notice as after service, in case of bad experience with component.
2015-12-03 02:17:44 +00:00
echo ' < h2 > Did something go wrong ? Are you disappointed ? </ h2 >
< p > Please let me know at < a href = " mailto:info@vdm.io " > info @ vdm . io </ a >.
< br /> We at Vast Development Method are committed to building extensions that performs proficiently ! You can help us , really !
< br /> Send me your thoughts on improvements that is needed , trust me , I will be very grateful !
< br /> Visit us at < a href = " https://www.vdm.io/ " target = " _blank " > https :// www . vdm . io /</ a > today !</ p > ' ;
2015-08-24 20:22:07 +00:00
}
/**
* method to update the component
*
* @ return void
*/
function update ( $parent )
{
}
/**
* method to run before an install / update / uninstall method
*
* @ return void
*/
function preflight ( $type , $parent )
{
2017-04-08 18:35:55 +00:00
// get application
$app = JFactory :: getApplication ();
// is redundant ...hmmm
2015-08-24 20:22:07 +00:00
if ( $type == 'uninstall' )
2017-04-08 18:35:55 +00:00
{
2015-08-24 20:22:07 +00:00
return true ;
}
2017-04-08 18:35:55 +00:00
// the default for both install and update
2015-08-24 20:22:07 +00:00
$jversion = new JVersion ();
2017-04-08 18:35:55 +00:00
if ( ! $jversion -> isCompatible ( '3.6.0' ))
2015-12-03 02:17:44 +00:00
{
2017-04-08 18:35:55 +00:00
$app -> enqueueMessage ( 'Please upgrade to at least Joomla! 3.6.0 before continuing!' , 'error' );
2015-08-24 20:22:07 +00:00
return false ;
}
2017-04-08 18:35:55 +00:00
// do any updates needed
if ( $type == 'update' )
{
}
// do any install needed
if ( $type == 'install' )
{
}
2015-08-24 20:22:07 +00:00
}
/**
* method to run after an install / update / uninstall method
*
* @ return void
*/
function postflight ( $type , $parent )
{
2015-12-03 02:17:44 +00:00
// set the default component settings
2015-08-24 20:22:07 +00:00
if ( $type == 'install' )
2015-12-03 02:17:44 +00:00
{
2015-08-24 20:22:07 +00:00
// Get The Database object
$db = JFactory :: getDbo ();
// Create the look content type object.
$look = new stdClass ();
$look -> type_title = 'Demo Look' ;
$look -> type_alias = 'com_demo.look' ;
$look -> table = '{"special": {"dbtable": "#__demo_look","key": "id","type": "Look","prefix": "demoTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}' ;
2017-04-08 18:35:55 +00:00
$look -> field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "metadata","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "metakey","core_metadesc": "metadesc","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","description":"description","alias":"alias","dateofbirth":"dateofbirth","website":"website","mobile_phone":"mobile_phone","add":"add","image":"image","email":"email","not_required":"not_required"}}' ;
2015-08-24 20:22:07 +00:00
$look -> router = 'DemoHelperRoute::getLookRoute' ;
$look -> content_history_options = '{"formFile": "administrator/components/com_demo/models/forms/look.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","not_required"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","add","not_required"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}' ;
2016-02-20 20:19:24 +00:00
// Set the object into the content types table.
$look_Inserted = $db -> insertObject ( '#__content_types' , $look );
2015-08-24 20:22:07 +00:00
// Install the global extenstion params.
$query = $db -> getQuery ( true );
// Field to update.
$fields = array (
2017-04-08 18:35:55 +00:00
$db -> quoteName ( 'params' ) . ' = ' . $db -> quote ( '{"autorName":"Llewellyn van der Merwe","autorEmail":"info@vdm.io","check_in":"-1 day","save_history":"1","history_limit":"10","uikit_load":"1","uikit_min":"","uikit_style":""}' ),
2015-08-24 20:22:07 +00:00
);
// Condition.
$conditions = array (
2016-03-05 22:57:11 +00:00
$db -> quoteName ( 'element' ) . ' = ' . $db -> quote ( 'com_demo' )
2015-08-24 20:22:07 +00:00
);
$query -> update ( $db -> quoteName ( '#__extensions' )) -> set ( $fields ) -> where ( $conditions );
$db -> setQuery ( $query );
2015-12-03 02:17:44 +00:00
$allDone = $db -> execute ();
2017-04-08 18:35:55 +00:00
// Get Application object
$app = JFactory :: getApplication ();
$app -> enqueueMessage ( 'First set the components global settings and permissions in the <b>Options</b> area, or the front-end of the component will not work as expected. <br />Please note that each view on the front-end has access and permissions, so if you would like the public to access those views they must be given the access and permission.' , 'Info' );
2015-12-03 02:17:44 +00:00
echo ' < a target = " _blank " href = " https://www.vdm.io/ " title = " Demo " >
2017-08-21 12:17:01 +00:00
< img src = " components/com_demo/assets/images/vdm-component.jpg " />
2015-12-03 02:17:44 +00:00
</ a > ' ;
}
// do any updates needed
if ( $type == 'update' )
{
2016-02-20 20:19:24 +00:00
// Get The Database object
$db = JFactory :: getDbo ();
// Create the look content type object.
$look = new stdClass ();
$look -> type_title = 'Demo Look' ;
$look -> type_alias = 'com_demo.look' ;
$look -> table = '{"special": {"dbtable": "#__demo_look","key": "id","type": "Look","prefix": "demoTable","config": "array()"},"common": {"dbtable": "#__ucm_content","key": "ucm_id","type": "Corecontent","prefix": "JTable","config": "array()"}}' ;
2017-04-08 18:35:55 +00:00
$look -> field_mappings = '{"common": {"core_content_item_id": "id","core_title": "name","core_state": "published","core_alias": "alias","core_created_time": "created","core_modified_time": "modified","core_body": "null","core_hits": "hits","core_publish_up": "null","core_publish_down": "null","core_access": "access","core_params": "params","core_featured": "null","core_metadata": "metadata","core_language": "null","core_images": "null","core_urls": "null","core_version": "version","core_ordering": "ordering","core_metakey": "metakey","core_metadesc": "metadesc","core_catid": "null","core_xreference": "null","asset_id": "asset_id"},"special": {"name":"name","description":"description","alias":"alias","dateofbirth":"dateofbirth","website":"website","mobile_phone":"mobile_phone","add":"add","image":"image","email":"email","not_required":"not_required"}}' ;
2016-02-20 20:19:24 +00:00
$look -> router = 'DemoHelperRoute::getLookRoute' ;
$look -> content_history_options = '{"formFile": "administrator/components/com_demo/models/forms/look.xml","hideFields": ["asset_id","checked_out","checked_out_time","version","not_required"],"ignoreChanges": ["modified_by","modified","checked_out","checked_out_time","version","hits"],"convertToInt": ["published","ordering","add","not_required"],"displayLookup": [{"sourceColumn": "created_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"},{"sourceColumn": "access","targetTable": "#__viewlevels","targetColumn": "id","displayColumn": "title"},{"sourceColumn": "modified_by","targetTable": "#__users","targetColumn": "id","displayColumn": "name"}]}' ;
// Check if look type is already in content_type DB.
$look_id = null ;
$query = $db -> getQuery ( true );
$query -> select ( $db -> quoteName ( array ( 'type_id' )));
$query -> from ( $db -> quoteName ( '#__content_types' ));
$query -> where ( $db -> quoteName ( 'type_alias' ) . ' LIKE ' . $db -> quote ( $look -> type_alias ));
$db -> setQuery ( $query );
$db -> execute ();
// Set the object into the content types table.
if ( $db -> getNumRows ())
{
$look -> type_id = $db -> loadResult ();
$look_Updated = $db -> updateObject ( '#__content_types' , $look , 'type_id' );
}
else
{
$look_Inserted = $db -> insertObject ( '#__content_types' , $look );
}
2015-12-03 02:17:44 +00:00
echo ' < a target = " _blank " href = " https://www.vdm.io/ " title = " Demo " >
2017-08-21 12:17:01 +00:00
< img src = " components/com_demo/assets/images/vdm-component.jpg " />
2015-12-03 02:17:44 +00:00
</ a >
2017-04-08 18:35:55 +00:00
< h3 > Upgrade to Version 2.0 . 0 Was Successful ! Let us know if anything is not working as expected .</ h3 > ' ;
2015-12-03 02:17:44 +00:00
}
2015-08-24 20:22:07 +00:00
}
}