Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F805324
modules_event_handler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Feb 27, 1:55 AM
Size
4 KB
Mime Type
text/x-php
Expires
Sat, Mar 1, 1:55 AM (28 m, 44 s)
Engine
blob
Format
Raw Data
Handle
577480
Attached To
rINP In-Portal
modules_event_handler.php
View Options
<?php
/**
* @version $Id: modules_event_handler.php 14787 2011-11-23 13:25:06Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
ModulesEventHandler
extends
kDBEventHandler
{
/**
* Builds item
*
* @param kEvent $event
* @access protected
*/
function
OnItemBuild
(&
$event
)
{
$this
->
Application
->
SetVar
(
$event
->
getPrefixSpecial
(
true
).
'_id'
,
$event
->
Special
);
parent
::
OnItemBuild
(
$event
);
}
/**
* Apply any custom changes to list's sql query
*
* @param kEvent $event
* @return void
* @access protected
* @see kDBEventHandler::OnListBuild()
*/
protected
function
SetCustomQuery
(&
$event
)
{
$object
=&
$event
->
getObject
();
/* @var $object kDBList */
if
(
$event
->
Special
)
{
$object
->
addFilter
(
'current_module'
,
'%1$s.Name = '
.
$event
->
Special
);
}
$object
->
addFilter
(
'not_core'
,
'%1$s.Name <> "Core"'
);
}
function
mapEvents
()
{
parent
::
mapEvents
();
$this
->
eventMethods
[
'OnMassApprove'
]
=
'moduleAction'
;
$this
->
eventMethods
[
'OnMassDecline'
]
=
'moduleAction'
;
}
/**
* Disabled modules, but not In-Portal
*
* @param kEvent $event
*/
function
moduleAction
(&
$event
)
{
if
(
$this
->
Application
->
CheckPermission
(
'SYSTEM_ACCESS.READONLY'
,
1
))
{
$event
->
status
=
kEvent
::
erFAIL
;
return
;
}
$object
=&
$event
->
getObject
(
Array
(
'skip_autoload'
=>
true
)
);
/* @var $object kDBItem */
$ids
=
$this
->
StoreSelectedIDs
(
$event
);
if
(!
$ids
)
{
return
;
}
$updated
=
0
;
$status_field
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'StatusField'
);
$status_field
=
array_shift
(
$status_field
);
foreach
(
$ids
as
$id
)
{
$object
->
Load
(
$id
);
if
(
in_array
(
$id
,
Array
(
'In-Portal'
,
'Core'
))
||
!
$object
->
isLoaded
())
{
// don't allow any kind of manupulations with kernel
// approve/decline on not installed module
continue
;
}
$enabled
=
$event
->
Name
==
'OnMassApprove'
?
1
:
0
;
$object
->
SetDBField
(
$status_field
,
$enabled
);
if
(!
$object
->
GetChangedFields
())
{
// no changes -> skip
continue
;
}
if
(
$object
->
Update
())
{
$updated
++;
$sql
=
'UPDATE '
.
TABLE_PREFIX
.
'ImportScripts
SET Status = '
.
$enabled
.
'
WHERE Module = "'
.
$object
->
GetDBField
(
'Name'
)
.
'"'
;
$this
->
Conn
->
Query
(
$sql
);
}
else
{
$event
->
status
=
kEvent
::
erFAIL
;
$event
->
redirect
=
false
;
break
;
}
}
if
(
$updated
)
{
$event
->
status
=
kEvent
::
erSUCCESS
;
$event
->
setRedirectParams
(
Array
(
'opener'
=>
's'
),
true
);
$this
->
Application
->
DeleteUnitCache
();
$this
->
Application
->
DeleteSectionCache
();
$event
->
SetRedirectParam
(
'RefreshTree'
,
1
);
}
}
/**
* Occurs after list is queried
*
* @param kEvent $event
*/
function
OnAfterListQuery
(&
$event
)
{
parent
::
OnAfterListQuery
(
$event
);
$modules_helper
=&
$this
->
Application
->
recallObject
(
'ModulesHelper'
);
/* @var $modules_helper kModulesHelper */
$new_modules
=
$modules_helper
->
getModules
(
kModulesHelper
::
NOT_INSTALLED
);
if
(!
$new_modules
||
$this
->
Application
->
RecallVar
(
'user_id'
)
!=
USER_ROOT
)
{
return
;
}
require_once
FULL_PATH
.
'/core/install/install_toolkit.php'
;
$toolkit
=
new
kInstallToolkit
();
$object
=&
$event
->
getObject
();
/* @var $object kDBList */
foreach
(
$new_modules
as
$module
)
{
$module_record
=
Array
(
'Name'
=>
$toolkit
->
getModuleName
(
$module
),
'Path'
=>
'modules/'
.
$module
.
'/'
,
'Version'
=>
$toolkit
->
GetMaxModuleVersion
(
'modules/'
.
$module
.
'/'
),
'Loaded'
=>
0
,
'BuildDate'
=>
null
,
);
$object
->
addRecord
(
$module_record
);
}
}
}
Event Timeline
Log In to Comment