SugarCRM Mass removal of custom fields - sugarcrm

I have a few hundred custom fields to delete in an older version of SugarCRM. Is very labor intensive to delete through web interface...
Can this be done directly by deleting files in the instalation (vardefs, anything else?)
This is similar to [question asked earlier] (revert the custom fields made by sugarCRM), but was solved by using web interface for a few fields.
I can easily write a script then to remove the fields from the {table_name}_cstm tables...

You can try something like that (should be execute in a SugarCRM environment like an entryPoint and with an admin user)
$fieldsByModule = array(
'Accounts' => array(
'field_1_c',
'field_2_c',
),
'Contacts' => array(
'field_1_c',
'field_2_c',
),
);
require_once('modules/DynamicFields/DynamicField.php');
foreach ($fieldsByModule as $moduleName => $fields) {
foreach($fields as $field){
$dyField = new DynamicField();
$dyField->bean = BeanFactory::getBean($moduleName);;
$dyField->module = $moduleName;
$dyField->deleteField($field);
}
}
Live coding without test the code but the core of the process should be near like that.

Related

TCA Icon overlay in typo3 backend

I’m working on an extension where I synchronise some data to another database and I wanted to show this in the backend using a TCA icon overlay. Sadly I could not find out how to do this. I thought about using ‘ctrl’=>‘typeicon_classes’ (using the state field of my table to choose an icon), this works for the default (non synchronised element) but I cannot figure out how to set an overlay. Any idea on how to do this?
My TCA configuration looks like this:
'ctrl' => [
...
'typeicon_column' => 'state',
'typeicon_classes' => [
'new' => 'mimetypes-x-content-login',
'synced' => 'mimetypes-x-content-login-overlay-approved',
]
],
The "synced" part does not work as expected. What I would expect is to either add the overlay at the end of the icon or by adding it with a whitespace but both did not work.
Any help is appreciated.
PS: I really just need this in the TYPO3 backend, the obvious solution for frontend is to use fluid or PHP but I don't think this suits the TYPO3 Backend list.
You need to register your icon files.
Given your icon files are named content_login.svg and content_login_overlay_approved.svg located in directory /Resources/Public/Icons/ you can register these in ext_localconf.php as following:
if (TYPO3_MODE === 'BE') {
$icons = [
'mimetypes-x-content-login' => 'content_login.svg',
'mimetypes-x-content-login-overlay-approved' => 'content_login_overlay_approved.svg',
];
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
foreach ($icons as $identifier => $path) {
$iconRegistry->registerIcon(
$identifier,
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => 'EXT:YOUREXTENSIONNANME/Resources/Public/Icons/' . $path]
);
}
}
Adapt yourextensionname

Set Module name, Controller name, and Action name in Zend framework?

I recently started programming with Zend Framework.I want to change module name, controller name and action name of a module in my framework through coding, while coding in the same framework.
Its name is Application(module & controller) and I want to change it to Institute. Is this possible through coding?
I searched through Google for help, but either i couldn't find it or understand it properly. Any help would be appreciated.
This is really just a case of renaming things:
Update all namespaces from Application to Institute in all the classes in the module including the Module.php
Update the name of the controller and it's entry in config/module.config.php
Make sure you update the name of your view directory if you have one in the module, ie view/application/index etc to view/institute/index and make sure you update the entry in module.config.php to the same path
Update name of Application directory to Institute
Update the name in the array of modules in modules.config.php or if you are using an earlier version application.config.php from under the modules key.
That's all I can think of you would need to do
******** EDIT ********
So the basic idea would be as follows:
Add a console in a new module (I've used zend mvc console but you should probably use https://github.com/zfcampus/zf-console as mvc console is deprecated)
module.config.php
<?php
namespace Rename;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'console' => array(
'router' => array(
'routes' => array(
'rename-module' => array(
'options' => array(
'route' => 'module rename <moduleNameOld> <moduleNameNew>',
'defaults' => array(
'controller' => Controller\IndexController::class,
'action' => 'rename'
)
)
)
)
)
),
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
],
],
];
IndexController.php
<?php
namespace Rename\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Console\Request as ConsoleRequest;
use Zend\Mvc\Console\Controller\AbstractConsoleController;
class IndexController extends AbstractConsoleController
{
public function renameAction()
{
$request = $this->getRequest();
// Make sure that we are running in a console and the user has not tricked our
// application into running this action from a public web server.
if (!$request instanceof ConsoleRequest) {
throw new \RuntimeException('You can only use this action from a console!');
}
$moduleNameOld = $request->getParam('moduleNameOld');
$moduleNameNew = $request->getParam('moduleNameNew');
$module = file_get_contents(getcwd() . "/module/$moduleNameOld/src/Module.php", 'r+');
$updatedModule = str_replace($moduleNameOld, $moduleNameNew, $module);
file_put_contents(getcwd() . "/module/$moduleNameOld/src/Module.php", $updatedModule);
rename("module/$moduleNameOld", "module/$moduleNameNew");
}
}
This can be run like
php public/index.php module rename Application Institute
I've only done renaming the module here and renaming the namespace in the Module.php
to finish this off you would need to recursively find all .php files in the Application directory and loop over applying the string replace (which should be improved really). Then you could update the view and application level config too with similar logic and using the steps above.
The code I've written is pretty bad and probably insecure but might help you along the way

Can't Relate Contact and Opportunity in SuiteCRM / SugarCRM CE

I'm working on a script to import data into SuiteCRM / SugarCRM CE. I need to create a Contact and an Opportunity. I then need to relate the two.
I have a many to many relationship between Contacts and Opportunities. Each contact should be able to create multiple opportunities. Each opportunity should be able to be assigned to multiple contacts.
When I run the code it says "1 Relationship(s) created", but when I check Suite there's nothing listed under the contact or opportunity subpanels.
FYI, I renamed the Opportunities module "Gigs" and am using this API Wrapper: github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class
Here's the code:
<?php
// Load Composer Dependencies for Sugar API Wrapper
require_once('vendor/autoload.php');
// Create Sugar Object
$sugar = new \Asakusuma\SugarWrapper\Rest;
// Set Sugar Connection Items
$sugar->setUrl('https://example.com/suitecrm/service/v2/rest.php');
$sugar->setUsername('User');
$sugar->setPassword('Pass');
// Connect to Sugar
$sugar->connect();
// Did something go wrong with the connection? Report it.
$error = $sugar->get_error();
if($error !== FALSE) {
return $error['name'];
}
// Ok... We're going to try and create a test entry in Sugar/Suite
// Create a Contact
$modules = 'Contacts';
// Set Values
$values = array(
'contact_type_c' => 'Prospect',
'lead_source' => 'Website',
'first_name' => 'Test',
'last_name' => 'Contact',
'phone_mobile' => '(123) 456-7890',
'email1' => 'test#test.com'
);
// Put it in Suite
$result = $sugar->set($modules, $values);
$contactID = $result['id'];
// Ok, now let's create a Opportunity
$modules = "Opportunities";
$values = array(
'name' => 'My Test Gig',
'sales_stage' => 'New Inquiry',
'amount' => '400'
);
$result = $sugar->set($modules, $values);
$gigID = $result['id'];
// Lastly, let's relate the two - HERE'S WHERE I HAVE PROBLEMS!
// Set Relationship
$moduleName = 'Contacts';
$moduleID = $contactID;
$linkFieldName = 'opportunities';
$relatedIDs = array($gigID);
$nameValueList = array(); // Passing empty array because we don't have any fields that need it
$delete = 0;
$result = $sugar->set_relationship($moduleName, $moduleID, $linkFieldName, $relatedIDs, $nameValueList, $delete);
echo $result['created'] . " relationship(s) made";
?>
The Contact and Opportunity are created just fine. It's the relationship that's not happening.
Ugh... Ok, I get it.
I looked at the API documentation and was passing $relatedIDs back as an array. What I didn't realize is that the API was doing this as well. So what got passed into Suite was a multidimensional array instead of a single array.

creating web services for iphone and cakephp project

Is there any way to collaborate Cakephp project with Iphone. Like: retrieving json data with cakephp models as WebServices in iphone. The aim behind this question is to use the cakephp code rather then creating WebServices differently.
Your help will be appreciated, Thanks!
Cakephp is a framework that outputs json data as much as like any other php frameworks out there.
You have to write functiosn like there:
public function api_get_release_tracks($release_id = null) {
if($release_id) {
$tracks = $this->Track->find('all', array( //sql queries are better here
'fields' => array('id', 'name', 'duration', 'duration_str',
'sample_audio', 'price', 'local_price'),
'conditions' => array('release_id' => $release_id),
'order' => array('position ASC')
));
$this->set('tracks', $tracks);
$this->set('_serialize', 'tracks');
}
}
Then you can get the json output in this url:
http://localhost:8090/{api name in cofig}/{controller name}/{things after api_ in function name}/{input parameters}.json
read more in here
Also you can alter the routing to change the name
api
to anything in
Configure::write('Routing.prefixes', array('master', 'api'));
in core.php in app/config

cake php habtm select does not set selected values

Hello I have several troubles with HABTM and Form.
I am using CakePHP 2.3 and PHP 5.3.3
This is my code situation for the understanding of the scenario: Albums and Singles related with a HABTM relation. Albums cointains many Singles and Singles belongs to many Albums.
Model Album.php ( don't care about raisins: is my personal plugin for managing images )
App::uses('Raisin', 'Raisins.Model');
App::uses('PastryBehavior', 'Raisins.Model/Behavior');
class Album extends AppModel
{
public $name = 'Album';
public $actsAs = array(
'Tags.Taggable',
'Utils.Sluggable' => array(
'label' => 'title'
),
'Raisins.Pastry',
'SrEngine.Indexable',
'SrEngine.HitCounter'
);
public $hasOne = array(
'Image' => array('className' => 'Raisins.Raisin')
);
public $hasAndBelongsToMany = array(
'Single'
);
public $belongsTo = array(
'Users.User'
);
}
Controller AlbumsController.php ( edit part )
$this->request->data = $this->Album->read(null, $id);
$this->set('singles',$this->Album->Single->find('list'));
View
<?php echo $this->Form->input('Single',array('class' => 'span12','label' => 'Singoli' ) ); ?>
In the view I see the select populated from the values coming from the controller singles set, but the selected item, previously saved, is not highlighted.
Consider that in the database the habtm table contains the correct row populated with the data saved.
I read , somewehere in the middle, that some previous version of cake, prior to 2.3, used to have some problem related to habtm form select input.
I am very stuck at this because I have almost tried every known workaround without sorting any positive effect.
Any help, hint would be very appreciated.
Thanks in advance
Rudy