How to Reference a Global Variable within another Global Variable in extensions.conf? - configuration-files

In extensions.conf, can I reference one global variable within another?
[globals]
GROUP1=SIP/3333&SIP/3334&SIP/3335
GROUP2=SIP/4442&SIP/4441&SIP/4442
GROUP3=SIP/5553&SIP/5550&SIP/5556
Like this?
EMERGENCY=${GROUP1}&${GROUP2}&${GROUP3}|9999|30
If not, how can I do the equivalent?

Yes, this is completely doable. As arheops mentioned, the values for the variables are substituted when an expression is evaluated in RTL order.
Example dialplan:
[general]
[globals]
TEST1=SIP/111&SIP/222
TEST2=SIP/333&SIP/444
TEST_GROUP=${TEST1}&${TEST2}
[default]
exten => 1,1,NoOp()
same => n,NoOp(${TEST1})
same => n,NoOp(${TEST2})
same => n,NoOp(${TEST_GROUP})
same => n,Dial(${TEST_GROUP})
same => n,Hangup()
exten => 2,1,NoOp()
same => n,Wait(5)
same => n,Hangup()
Example execution using a fresh checkout from Asterisk 1.8, showing the variable values:
*CLI> channel originate Local/1#default extension 2#default
-- Executing [1#default:1] NoOp("Local/1#default-505e;2", "") in new stack
-- Executing [1#default:2] NoOp("Local/1#default-505e;2", "SIP/111&SIP/222") in new stack
-- Executing [1#default:3] NoOp("Local/1#default-505e;2", "SIP/333&SIP/444") in new stack
-- Executing [1#default:4] NoOp("Local/1#default-505e;2", "SIP/111&SIP/222&SIP/333&SIP/444") in new stack
-- Executing [1#default:5] Dial("Local/1#default-505e;2", "SIP/111&SIP/222&SIP/333&SIP/444") in new stack

You can't. Just create enother logic or external script to do create dialplan file

Related

How to change the default order of the sub panels in the opportunities module

I have a need to change the default order of the sub panels in the opportunities module. I have been looking for a solution for a while and have not found a solution that works.
I am using SugarCRM CE 6.5.13
Thanks in advance.
Your question is actually unclear. Are you asking for the order of a subpanel meaning how to place one subpanel above another. Or is your question concerning the order of the data inside a subpanel?
A fast response to both is:
in {MainModule}/metadata/subpaneldefs.php there should be the sort order declared for the subpanel like this:
$layout_defs[{MainModule}] = array(
// list of what Subpanels to show in the DetailView
'subpanel_setup' => array(
'{TheSubpanel}' => array(
'order' => 1, // influences the place of the subpanel relative to the other subpanels
'module' => '{TheSubpanel}',
'subpanel_name' => 'default', // attention please check the subpanel module to make sure there is not another setting overriding this setting
'sort_order' => 'desc',
'sort_by' => 'date_entered',
...
check also the file defined above that contains the subpanels fields. In this case it can be found in {TheSubpanel}/metadata/subpanels/default.php
$module_name = '{TheSubpanel}';
$subpanel_layout = array(
'top_buttons' => array(
'where' => '',
'sort_order' => 'desc',
'sort_by' => 'date_entered',
Please consider that after a change you need to run 'rebuild & repair' and if you manually clicked on a sort field then you should clear your cookie cache and log in again too.
There are other questions on stack overflow concering this like how-to-change-default-sort-in-custom-subpanel-sugarcrm
If you do not want code level customization then you can just drag and drop the sequence of subpanels on detail view of record. The sequence of subpanel will be saved.

How do I create a Catalyst::Model::DBIC::Schema from a DBIC::Schema?

Total lack of documentation makes this difficult..
Essentially, I have
package MyApp::Schema;
sub new_schema {
__PACKAGE__->connect(...)
}
Then I have
package MyCatApp::Model::MyApp;
use Moose;
extends 'Catalyst::Model::DBIC::Schema';
## what here;
_PACKAGE__->make_immutable;
How do I make this work? If I have this in my config...
<Model::MyApp>
schema_class MyApp::Schema
traits Caching
user_defined_schema_accessor foo
</Model::MyApp>
I get the following error:
BEGIN failed--compilation aborted at MyCatapp.psgi line 4, line 1.
Error while loading MyCatapp.psgi: Couldn't instantiate component "Either ->config->{connect_info} must be defined for MyCatApp::Model::MyApp or MyApp::Schema must have connect info defined on it.
But adding sub connect_info {} in MyApp::Schema does not change anything. That error is generated on line 480 of this file.
That method seems to be looking at $schema_class->storage->connect_info which I believe is an method on an instantiated object, and not a function in the package. However, if I try to set
__PACKAGE__->config('schema_class', MyApp::Schema->new_schema)
I then get...
Error while loading : Couldn't instantiate component "MyCatApp::Model::MyApp", "Attribute (schema_class) does not pass the type constraint because: Validation failed for 'Catalyst::Model::DBIC::Schema::Types::SchemaClass' with value MyApp::Schema=HASH(0xb4a5ff0) at /usr/local/lib/perl/5.18.2/Moose/Exception.pm line 37
So, how do I go about doing this...
So.. I'm not sure this is right so I won't mark it as accepted but I was pretty damn close.. This line is dead on..
__PACKAGE__->config('schema_class', MyApp::Schema->new_schema)
And the code is in place for that to work, as per the link above on line 480 of Catalyst::Model::DBIC::Schema. However, the type is wrong..
The type of schema_class is SchemaClass. And, SchemaClass is defined here
subtype SchemaClass,
as LoadableClass,
where { $_->isa('DBIx::Class::Schema') };
Now, SchemaClass is a subtype of a MooseX::Types::LoadableClass which essentially just takes a package name and requires it..
The problem is LoadableClass doesn't take an instance of DBIC::Schema. Anyway.. I was just changed it too..
has schema_class => (
is => 'ro',
isa => 'Object',
required => 1
);
Now I can stuff an instantiated schema into schema_class and pass the conditional if($schema_class->storage && $schema_class->storage->connect_info).
I filed a bug on this here
You could instantiate the connection info in your MyApp::Schema by in it doing:
__PACKAGE__->connection(#your_connection_details);
This will set up a Storage on the class itself, not a schema object. This will then pass the Catalyst::Model::DBIC::Schema check and work successfully. I think this achieves what you're after without changing the underlying classes (though might depend on the details not included).
From the documentation you referenced, your MyCatApp::Model::MyApp would look like this:
__PACKAGE__->config(
schema_class => 'MyApp::Schema',
connect_info => {
dsn => 'dbi:Pg:dbname=mypgdb',
user => 'postgres',
password => '',
pg_enable_utf8 => 1,
on_connect_do => [
'some SQL statement',
'another SQL statement',
],
}
);
And in your controller, you would:
my $db = $c->model('MyApp');

In Perl, what's the meaning of this code " has 'absolute_E' => (is => 'rw',default => sub {0} );"

The following codes make me so confused, I can't find any related knlowledge about the syntax "has ,is ,default, lazy". Can anybody make a detailed explain for me, best wishes.
has 'absolute_E' => (is => 'rw', default => sub {0} );
has 'retract_speed_mm_min' => (is => 'lazy');
has 'retract_speed_mm_min' => (is => 'lazy');
Judging by this line, this is probably a Moo class. To confirm this, have a look near the top of the file, and you should see something like use Moo.
Moo is an object-oriented framework for Perl. I'll assume you understand OO concepts.
Some historical background: Perl 5 has built-in OO capabilities, however it can get a little cumbersome at times. Then Moose came around as an improved way of OOP in Perl. But Moose was also quite heavy, with a compile-time cost, so Moo (and also Mouse just before it) came after that as something of a lighter-weight subset of Moose.
has is for defining attributes in your class.
has 'absolute_E' => ( is => 'rw', default => sub {0} );
This defines an attribute named absolute_E.
is => 'rw' means it is readable and writable, which means you can do this:
my $value = $obj->absolute_E; # gets the value
$obj->absolute_E($value); # sets the value
When you instantiate the object, you can supply a value for the attribute:
my $obj = My::Class->new( absolute_E => 5 );
But if you don't supply anything then absolute_E is set to 0 by default.
This second attribute has a few more things:
has 'retract_speed_mm_min' => (is => 'lazy');
This is short form for:
has 'retract_speed_mm_min' => (
is => 'ro',
lazy => 1,
builder => '_build_retract_speed_mm_min'
);
This attribute is readonly which means you can't change its value after construction. But you can supply a value at construction as before.
The builder is another way of providing a default value. It requires the class to have a separate method named _build_retract_speed_mm_min that should return the default value.
lazy works with builder. It means that the attribute should not be set by the builder until it the attribute is used. The delay may be used because the builder depends on other attributes in order to build this attribute's value.
There's a lot more in Moo and Moose. I would suggest reading http://modernperlbooks.com/books/modern_perl_2014/07-object-oriented-perl.html and https://metacpan.org/pod/Moose::Manual and https://metacpan.org/pod/Moo.
That code basically equals
has ('absolute_E', 'is', 'rw', 'default', sub {0} );
has ('retract_speed_mm_min', 'is', 'lazy');
And has looks like a user-defined subroutine.
=> is almost the same as ,:
The => operator is a synonym for the comma except that it causes a word on its left to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores.

are there iterators and loops in puppet?

When I define(?) a resource e.g. to ensure dir structure, are there any loops available?
Like that:
for X in [app1,app2] do:
file { '/opt/app/' + X:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0644',
}
I have tens of directories and I am really tired with declaring it in puppet.. It would take 15 LOC of bash.
Any ideas?
Older versions of the puppet language have no support for loops.
But you can use an array instead of a simple string for the title and declare several resources at the same time with the same params:
$b = '/opt/app'
file { [ "$b/app1", "$b/app2" ]:
ensure => directory,
owner => 'root',
group => 'root',
mode => 0644,
}
You can also declare many resources of the same type with different params by ending each resource with a ;, which is a bit more compact than repeating the file and the {s and }s:
file {
[ "$b/app1", "$b/app2" ]:
ensure => directory,
owner => 'root',
group => 'root',
mode => 0755;
[ "$b/app1/secret", "$b/app2/secret" ]:
ensure => directory,
owner => 'root',
group => 'root',
mode => 0700;
}
In the specific case of files, you can set up a source and use recursion:
file { "/opt/app":
source => "puppet:///appsmodule/appsdir",
recurse => true;
}
(that would require having a source of that directory structure for puppet to use as the source)
You can define a new resource type to reuse a portion of the param multiple times:
define foo {
file {
"/tmp/app/${title}":
ensure => directory,
owner => 'root',
mode => 0755;
"/tmp/otherapp/${title}":
ensure => link,
target => "/tmp/app/${title}",
require => File["/tmp/app/${title}"]
}
}
foo { ["app1", "app2", "app3", "app4"]: }
Starting with Puppet 2.6, there's a Ruby DSL available that has all the looping functionality you could ask for: http://www.puppetlabs.com/blog/ruby-dsl/ (I've never used it, however). In Puppet 3.2, they introduced some experimental loops, however those features may change or go away in later releases.
As of version 3.2 there are lambdas
You must set parser = future in puppet.conf.
$a = [1,2,3]
each($a) |$value| { notice $value }
Another option for declaring multiple defined types is create_resources. Pass it a hash of hashes:
create_resources(file, {
'/tmp/test1' => {
ensure => directory,
owner => 'root',
group => 'root',
mode => '0644',
},
'/tmp/test2' => {
ensure => directory,
owner => 'www-data',
group => 'www-data',
mode => '0755',
},
})
As of Puppet 4 (and the "future parser" of late versions of Puppet 3) the Puppet DSL has iteration functions similar in form and function to some of the methods of Ruby arrays and hashes:
each - evaluates a block of code (formally, a lambda) for each element of an array or hash
filter - applies a lambda to each element of an array or hash and returns an array or hash of those for which the lambda evaluated to true
map - applies a lambda to each element of an array or hash, and returns an array of the results
reduce - applies a lambda to each element of an array or hash to build up a single result, which it returns
There is no indexed for loop along the lines of C's or Java's, but you can combine array sectioning with any of the functions above to achieve iteration over a subset of a data structure. There is no indefinite iteration along the lines of a C or Java while loop.
Of course, you can still use the resource-centric approaches described in other answers, and sometimes one of those is indeed the best available approach. You cannot any longer use Ruby DSL, however; it is removed altogether from Puppet 4. Among the iteration functions, the ability to define custom functions, the ascension of data-centric approaches into favor, and all Puppet's historic standard features, Ruby DSL seems not much missed.
Yes. "Ruby DSL" could help, just use file extension ".rb" instead of ".pp" in manifest and you can define puppet "type" like this:
define 'myapps::structure', :applist do
#applist.each do |app|
file( #name+'/'+app,
:ensure => directory,
:owner => 'root',
:group => 'root',
:mode => '0644')
end
end
Classes and nodes also can be defined in similar way. Notice however that this feature is deprecated since release 3

Why does Perl's CGI::FormBuilder complain about 'No options specified for select'?

I get this error from my CGI script:
my_circle.pl: [FormBuilder] Warning: metro: No options specified for 'select' field at /home/ecoopr/ecoopr.com/CPAN/CGI/FormBuilder.pm line 1407, referer: http://kkarnam.ecoopr.dyndns.org:880/home.pl
Can you suggest me what might be the problem?
As the error message says, you are probably trying to construct a select form widget without specifying any options.
Find out what is triggering that part of CGI::FormBuilder. You can use something like Carp::Always to turn all errors and warnings into stack traces so you can work back to the line of code that started the problem.
The relevant code is the anonymous hash construction in the prepare method, which looks like its expecting you to provide some options for select:
1406 # Create a struct for each field
1407 $tmplvar{field}{"$field"} = {
1408 %$field, # gets invalid/missing/required
1409 field => $field->tag,
1410 value => $value[0],
1411 values => \#value,
1412 options => [$field->options],
1413 label => $field->label,
1414 type => $field->type,
1415 comment => $field->comment,
1416 nameopts => $field->nameopts,
1417 cleanopts => $field->cleanopts,
1418 };
Make sure there are some options defined for selects.
For example, consider this form field definition:
$form->field(
name => 'dept_id',
label => 'Dept',
type => 'select',
options => \#dept_options,
required => 1,
);
If the #dept_options array is empty, CGI::FormBuilder will issue the warning.