CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Site deployment via the API
Pages: [1]

Author Topic: Site deployment via the API  (Read 1365 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Site deployment via the API
May 21, 2012, 04:30:04 am
Joe Murray has asked me to spec out what the API requires for it to be possible to do site config via the API

I've had a first cut of it here

http://wiki.civicrm.org/confluence/display/CRMDOC41/Spec+for+profile+configuration

Please take a look & check discussion so far on the IRC log (where I kind of explain it)

http://irc.civicrm.org/logs/%23civicrm.log.2012-05-21.txt

Feedback = welcome!
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Site deployment via the API
May 21, 2012, 06:14:12 am
Quote
[11:00] <xavier_d> eileen, that's way more than profile config that you are listing
[11:00] <xavier_d> (eg import/export mapping)
[11:00] <eileen> yep - not sure that's required
[11:01] <eileen> I didn't add an action for that
[11:02] <eileen> (the ones @ the top I added actions for - the others are hopefully either covered by the actions or not required
[11:02] <xavier_d> but good to see what's missing, no matter what
[11:02] <xavier_d> did you already think about the name/syntax for the missing apis?
[11:03] <eileen> nope - took quite a while just to get that much order into it all
[11:03] <eileen> I went throught the UI one day & couldn't face it again for several days :-)
[11:04] <xavier_d> id/task id, that's something internal for you or is this meaning something for everyone?
[11:04] <eileen> yep - those are mostly about sorting in Excel :-)
[11:05] <eileen> (& making sure if I sorted it wrong I could get the original order back )
[11:06] <eileen> So, I'm thinking stage 1 would be to add the settings api & a way to load it from xml - with probably domain + loc_block + chain too to test the xml syntax
[11:06] <eileen> not sure the xml would be part of API or just a drush command
[11:06] <xavier_d> for the syntax it works already on json (including chaining)
[11:07] <eileen> hmm - is json used to ship config in the way xml is? I guess Drupal would just do arrays
[11:08] <xavier_d> not sure json is the right format indeed, just mentioning it. IMO the syntax is part or drush command, not the api
[11:08] <eileen> OK - seems a reasonable position
[11:08] <eileen> So, how on earth does one try to come up with any time estimate!
[11:10] <xavier_d> yes, quite a few moving parts. did you see if everything stored at the same place (eg. civicrm_setting) has the same BAO?
[11:10] <xavier_d> ie. not too hard to have something generic?
[11:11] <xavier_d> (this being said, enabling a component or list of available countries aren't going to have the same syntax at all)
[11:11] <eileen> well - I made some assumptions about which would be in settings table - I didn't check every value - some will be wrong
[11:13] <eileen> I think most settings will are serialized - so it will need to know if it is receiving an integer or string or array
[11:14] <eileen> So, maybe need to set up a way of describing settings (would probably include info currently stored in templates too)
[11:14] <eileen> ie. an xml for them
[11:16] <xavier_d> so starting with an settings -> xml converter?
[11:17] <eileen> Well, I was thinking about how the schema xml is stored & thinking about having one for the settings table maybe- so it's possible for the API (& other code) to understand the data-type of each setting
[11:18] <eileen> (of course maybe that aready exists in some way - haven't looked @ what the BAO does)
[11:21] <eileen> Well - I think I have to go to bed - will flick out an email encouraging others to look
[11:21] <xavier_d> actually, wondering if some of these "settings" should be exposed directly or is this more an implementation detail that should be abstracted for the api users. eg that the default country or the list of enabled country is stored in the settings is an implementation choice and could be moved to civicrm_country without breaking all the config scripts
[11:22] <xavier_d> eg. civicrm_api ('country','create', iso='us', is_default=>1)
[11:22] <xavier_d> and this does store it into settings
[11:23] <xavier_d> on the chaining, we might need different "actions" (eg create_if_not_exists)
[11:23] <xavier_d> or having options=>on_error_update
[11:23] <eileen> oh yeah - that's probably needed on chaining
[11:24] <eileen> the issue with stuff being moved is kind of about testing - ie. we need enough 'static' tests that we pick up changes & adapt the api to cope with them
[11:25] <eileen> (which will mean over time the API becomes increasingly cluttered & we need to start looking for excuses to move to v4 & ditch the clutter :-)
[11:25] <xavier_d> yeap, that's a problem with kind of have already with the constant api
[11:25] <eileen> Actually with 4.2 coming out I know of at least one schema change which we possibly should add api handling-cruft for - the change from civicrm_event.payment_processor_id to civicrm_event.payment_processor
[11:26] <xavier_d> where some stuff you can read from there but need to use optionvalue to modify
[11:26] <xavier_d> anyway, great work, will think about it
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Site deployment via the API
May 23, 2012, 02:40:54 pm
Thanks for your great start on this, Eileen. I've just put some further ideas on the wiki page.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Site deployment via the API
May 24, 2012, 05:10:28 pm
Quote
(10:20:54 AM) eileen: So, I chatted with Joe & his prioriteis are 1 - stuff in civicrm_settings, 2 some thing still in domain->config & 3) contribution page
(10:21:31 AM) eileen: I'm guessing that the things in domain->config (e.g. date format) are probably intended to be moved into settings before too long
(10:21:46 AM) totten: yeah. i think it would be better for us/him to push that along
(10:22:06 AM) totten: unless it's really important to support old versions of civi
(10:22:53 AM) eileen: Re the civicrm_settings table - It makes sense to me to create a civicrm_api('settings','create' ) action (& a 'real' update for when you don't have id)
(10:23:46 AM) eileen: but where I see an issue is that the value in civicrm_settings table is stored as a serialized array & I *think* that knowledge of what the variable is @ the moment is in the form layer
(10:24:10 AM) totten: right. it should be in some xml metadata -- like we do with sql schema
(10:24:42 AM) eileen: OK - so that was what I was trying to say in the emails
(10:24:57 AM) totten: right. i agree.
(10:25:22 AM) eileen: (did you understand that was what I was trying to say or did you just separately come to that conclusion?)
(10:26:00 AM) xavier_d1: beside, would help to move away the big serialise blob if we want to store on separate records
(10:26:29 AM) totten: eileen: both ;)
(10:26:32 AM) eileen: xavier_d1 - are you refering to the $domain->config blob
(10:26:53 AM) eileen: totten - yay - I wasn't clear if my mention of 2 sorts of xml had hopelessly muddied the picture
(10:27:26 AM) xavier_d1: eileen: made sense to use xml to define the structure
(10:27:48 AM) totten: xavier_d1: i think eileen was saying that the payload of some civicrm_setting rows contains serialized blobs
(10:28:17 AM) totten: actually, i guess all of them do...
(10:28:26 AM) eileen: So, I'm thinking it would be a case of 1) coming up with some sort of xml structure, 2) prototyping a settings form to run directly off it (with less in form layer) & 3 write an API for settings that uses the same for validation when settings
(10:29:13 AM) eileen: also, need to look @ what function does the equivalent of sql REPLACE INTO (ie. create or update as appropriate)
(10:29:48 AM) xavier_d1: totten: all the 39 rows contains serialise blob I think
(10:30:37 AM) eileen: If you look @ drupal config architecture (http://groups.drupal.org/node/191283 - which I believe was the thinking behind Civi)
(10:30:52 AM) eileen: they also allow you to store config on disk as xml
(10:31:38 AM) eileen: I would imagine that would be really cool, done @ the setting BAO level - but probably not phase 1 unless already in place.
(10:32:37 AM) eileen: then the next challenge would be tracking changes to the xml. ie. ideally whenever either the schema xml or settings xml changed there would be a ticket logged to assess the impact the impact of the change on the api

(10:33:32 AM) eileen: & as the settings & schema morphed over time we'd build up yucky long _civicrm_api_contact_create_legacyhandling() functions until we found an excuse to drop API v3 & all the legacy cruft

(10:35:25 AM) totten: eileen: building up legacy adapters for changes in settings xml doesn't sound appealing ;)
(10:35:43 AM) eileen: nope - but, any other options as it changes over time?
(10:35:48 AM) totten: i'd lean towards a "fail-fast, fail-hard" approach
(10:36:10 AM) eileen: so force people to adapt - I guess that's OK for settings
(10:36:58 AM) eileen: as in it's used for site set up - it's the ones like the change to event schema from processor_id to processor that we really should handle as a legacy setting
(10:37:15 AM) totten: right. the approach isn't appropriate for every piece of data, but it feels acceptable to me for the multi-site autoconfiguration stuff
(10:37:16 AM) eileen: otherwise - where is the claim that the api is more future proof than sql
(10:37:51 AM) xavier_d1: doesn't sound too weird that if the setting changes between civi versions you need to adjust the code
(10:38:16 AM) xavier_d1: eileen: is there already a way to know civicrm's version via the api?
(10:38:40 AM) xavier_d1: that's probably needed to know what setting can/can't be done
(10:38:46 AM) eileen: nope - that makes sense, so basically we equip the settings api (via xml descriptor) to do reasonable validation & then do that before anything get's written or roll back
(10:39:34 AM) eileen: version should be available from domain - as long as upgrade has been run
(10:40:31 AM) xavier_d1: well, kind of: config_backend":"a:81:{s:15:\"civiRelativeURL\";s:17:\"\/civicrm_staging\/\";s:10:\"lcMessages\";s:5:\"fr_FR\";s:25:\"monetaryThousandSeparator\";s:1:\"'\";s:20:\"monetaryDecimalPoint\";s:1:\".\";s:11:\"moneyformat\";s:6:\" %a %c\";s:16:\"moneyvalueformat\";s:3:\"%!i\";s:12:\"countryLimit\";a:229:{i:0;s:4:\"1228\";i:1;s:4:\"1070\";i:2;s:4:\"1068\";i:3;s:4:\"1064\";i:4;s:4:\"1240\";i:5;s:4:\"1239\";i:6;s:4:\"1237\";i:7;s:4:\"1235\"
(10:40:43 AM) eileen: there's a version field!

(10:41:03 AM) totten: you can also get version another way

(10:41:28 AM) totten: ie CRM_Utils_System::version(); -- which reads from a file
(10:42:01 AM) grobot: db version is db version, for upgrade you need to compare them
(10:42:22 AM) totten: right. for the uprade you compare them
(10:42:45 AM) eileen: So, one question there is whether we should think about making some util functions available via the API - e.g. civicrm_api('utils','getversion',$params); - & if we did that would it be possible to keep them sane

(10:42:59 AM) totten: but in the context of, say, an install profile -- would the two versions agree?
(10:44:15 AM) eileen: NB - I don't know if there are any potential positives from this but in drupal config it looks like drupal will read the config (d8) if in a dir called xml
(10:44:18 AM) eileen: called config
(10:45:00 AM) totten: wouldn't it be a bad idea to run any api call (settings or otherwise) when the db and code disagree
(10:45:12 AM) xavier_d1: civicrm_api ("settings","get", return= array("code_version","db_version"))
(10:45:21 AM) eileen: totten - that seems like a reasonable point of view
(10:45:34 AM) xavier_d1: totten: why would we be more restrictive than the UI?
(10:45:53 AM) eileen: OK - so code_version & db_version are not actually in the settings table though are they (xavier_d1)?
(10:46:18 AM) eileen: or are you saying they should be
(10:46:41 AM) xavier_d1: eileen: or that the api does fetch the info at the right place if not in setting
(10:47:18 AM) xavier_d1: ie. where this is stored shouldn't be the concern of the api user
(10:47:40 AM) eileen: hmm - maybe - but then we're starting off with something that almost feels like a hack to the new api
(10:48:27 AM) totten: ok, so xavier_d1 is saying that the db_version should be reported to downstream devs the same way as settings

(10:48:43 AM) totten: if we want that, then i think we should move that data from the domain backend to civicrm_setting
(10:49:08 AM) xavier_d1: totten: does it make sense to have it in domain anyway?
(10:49:38 AM) eileen: for 3.4 / 4.0 yes, after that I doubt it
(10:49:39 AM) xavier_d1: as in could it be different between domains of the same instance
(10:49:59 AM) eileen: (ie. I have sites with d6 & d7 plugged into the same civi - mostly as a transition)
(10:50:16 AM) eileen: but that's not really relevant as we're not expecting that to occur again
(10:50:34 AM) eileen: so, OK - settings table makes sense to me
(10:51:14 AM) totten: settings makes more sense to me; having multiple values for db_version (for domains) would be problematic
(10:51:39 AM) totten: the db_version is used to drive DB updates -- e.g. schema changes which apply to any/all domains that share a DB
(10:51:49 AM) xavier_d1: anyway, in the long term, most of config_backend in domain will migrate to settings, isn't it?
(10:52:12 AM) eileen: OK so I feel like we are fairly in agreement on the api side of it & the xml, what about testing - do we have any specific ideas
(10:52:44 AM) eileen: I guess we need to have an automated test that chugs through setting & getting the settings

(10:52:58 AM) xavier_d1: api: what's your feeling of "perverting/extending" getfields to expose the xml ?
(10:53:23 AM) xavier_d1: ie. show each setting as a separate attribute of the setting entity
(10:53:26 AM) eileen: I was thinking about a new function
(10:53:32 AM) eileen: getoptions
(10:53:35 AM) eileen: perhaps

(10:54:11 AM) xavier_d1: we agree that "usual getfields" doesn't make sense for settings, right?

(10:54:51 AM) totten: from the perspective of downstream dev,  it would be nice sugar to treat each setting as a different attribute on the singleton setting entity
(10:54:54 AM) eileen: no, you've possibly noticed that some fields now return options (e.g. activity.priority_id) but that doesn't make sense either I don't think
(10:55:11 AM) eileen: totten - say that again - in 3 sentences
(10:55:15 AM) xavier_d1: I think it will make it easier to discover if we use the same actions than usual
(10:55:19 AM) eileen: with more words
(10:55:23 AM) totten: e.g. civicrm_api('setting', 'set', array('mail_server'=>…, 'mail_port'=>…,'mail_user'.=>…))
(10:55:55 AM) xavier_d1: eileen: that would make sense as well on settings.getfields I think

(10:56:23 AM) xavier_d1: eg. outgoing mail is smtp, null, mail(), sendmail
(10:56:37 AM) totten: right. you would make it appear that way for all parts of the api -- CRUD and getfields
(10:56:55 AM) eileen: OK - so, the point there is that there is more than one field in that table - & that format doesn't cover them
(10:57:20 AM) eileen: are any of them important?
(10:57:58 AM) eileen: possibly domain_id & contact_id are -the rest can be derived from the XML I think
(10:57:59 AM) xavier_d1: totten: yes, but as it's a singleton no id

(10:59:16 AM) xavier_d1: eileen: the only one that has a contact_id is the navigation menu
(10:59:55 AM) totten: so would one use this api to set options in a multi-domain context?
(10:59:57 AM) eileen: yes, that seems to be the case. In which case it may make sense for a separate api for navigation menu when it's for a contact?
(10:59:59 AM) xavier_d1: totten: actually, might be that the id is the domain id and that it isn't (always) a singleton
(11:00:07 AM) totten: i.e. domain_id=2 has one value for mail-server and domain_id=3 has a different value
(11:00:17 AM) eileen: totten - yes -
(11:00:29 AM) xavier_d1: eileen: does it work?
(11:00:40 AM) eileen: or a better example is domain_group_id
(11:01:05 AM) eileen: xavier_d1 - yes, I think that would be OK - would it confuse people who are used to our current usage?
(11:01:26 AM) eileen: It would mean you could do a get & get the different domains indexed by their ids too

(11:02:09 AM) eileen: NB - are you thinking we still call the actions 'create', & 'get' & 'getfields' but just massage the table interpretation?
(11:02:40 AM) xavier_d1: eileen: yes, and I don't think I twist them too much
(11:03:02 AM) eileen: OK, I'm feeling OK with that -
(11:04:00 AM) eileen: nb - did you look @ the drupal architecture link?
(11:04:13 AM) totten: so do we need to be concerned that hte list of of per-domain and per-contact settings are probably different?
(11:04:39 AM) eileen: totten - yes for per-domain - although we could treat it as an id per x
(11:04:59 AM) eileen: for per-contact - not sure - if it's just navigation menu perhaps we should treat that differently
(11:05:53 AM) xavier_d1: is this really possible to have different navigation menues between users?

(11:06:09 AM) xavier_d1: (beside hiding due to permissions obviously)
(11:06:16 AM) eileen: esp as navigation menu doesn't seem to store the data in the same way - it feels like a shotgun marriage between settings data & navigation

(11:07:27 AM) eileen: like, only navigation uses contact_id & navigation doesn't use value but the were already co-habitating in the old preferences table so someone said they couldn't separate
(11:08:14 AM) eileen: So, I'm going to vote that the limit of the settings api is anything that is per-contact & that gets it's own api
(11:08:37 AM) xavier_d1: eileen +1
(11:10:06 AM) xavier_d1: and anyway, if we can manipulate the navigation via the api, that's hopefully going to be something different than value= 22k of serialized php that contains html that contains javascript
(11:10:28 AM) totten: eileen and xavier_d1 : just asked dlobo about why the two types of settings are stored in the same table
(11:10:31 AM) dlobo:  yes, but u dont want to recompute that 22K on every page load
(11:10:48 AM) dlobo: since navigation is displayed pretty much on all pages
(11:11:03 AM) xavier_d1: sure, It's for the setting, for the storing make sense
(11:11:14 AM) eileen: nope - I'm lost
(11:11:23 AM) totten: the basic design issue is that the programmer often doesn't care about whether settings are "per-domain", "per-contact', "per-group", etc
(11:11:56 AM) totten: the programmer wants to say "give me the active timezone" -- but the timezone might be a per-user preference or a per-domain default
(11:12:43 AM) totten: so you want one interface -- eg CRM_Core_BAO_Setting::getItem() -- which looks up the setting regardless of how the policies are designed
(11:14:00 AM) eileen: OK - so the options are to either have to set your contact & domain first & it will only let you get them in a call
(11:14:22 AM) xavier_d1: totten: 99% of the case that's single domain and navigation is the only case with contact id set
(11:14:22 AM) eileen: or, you do as Xavier suggested (for domain) & optionally set the domain a s 'id'
(11:14:57 AM) eileen: yes, that's the thing - navigation also appears not to use the value field - so it's very different (either that or the upgrade script mulched it)
(11:15:18 AM) eileen: but, do we forsee other settings that might involve contact
(11:15:47 AM) xavier_d1: so if civicm_api ("setting","get", array(return="timezone", id=1))
(11:16:15 AM) dlobo left the room (quit: Quit: dlobo).
(11:16:25 AM) xavier_d1: id can actually be optional if single domain or if we can guess the domain (eg via rest/ajax)
(11:16:35 AM) eileen: yep
(11:16:52 AM) eileen: & people dealing with multidomains understand it's a multi
(11:17:19 AM) xavier_d1: and instead of trying to make something complicated to cover things that don't exist, we decide it won't be dealt through this setting api if contact_id
(11:17:22 AM) eileen: but we'd want to support 'is_current_domain'
(11:17:38 AM) xavier_d1: eileen: if not set it's implicit
(11:17:48 AM) xavier_d1: (id not set I mean)
(11:17:51 AM) eileen: how do you return all then?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Site deployment via the API
May 24, 2012, 05:10:53 pm
Quote
(11:18:19 AM) xavier_d1: all what?
(11:18:30 AM) eileen: all the domains - let me pastebin it
(11:18:59 AM) totten: but there's a bit of potential ambiguity -- three different cases for asking "what's the timezone"
(11:19:44 AM) totten: i.e. "what is the default timezone for domain X [alt: current domain]"; "what is the default timezone for user  [alt: current user]"
(11:20:10 AM) totten: and "what is the effective/active timezone (after synthesizing any domain/user/hook/whatever)"
(11:20:35 AM) xavier_d1: totten: is this a real example (eg. can we have a tz per user?)
(11:21:05 AM) totten: i haven't heard of people doing that -- but dlobo said it was a motivational example behind the design
(11:21:13 AM) eileen: Ok xavier_d1 - this is what I thought you meant first - http://pastebin.com/ES4hLcmG
(11:21:14 AM) xavier_d1: but anyway:
(11:21:54 AM) eileen: (not a real example in that I think we're planning on using cms functionality for timezone)
(11:22:37 AM) xavier_d1: by default without id = what makes sense in the context, so either the effective/active timezone
(11:22:50 AM) xavier_d1: if id => tz of the domain

(11:23:05 AM) xavier_d1: and if one must, contact_id => tz of the user
(11:23:32 AM) xavier_d1: while keeping in mind than 99% of the case there is one and only one domain
(11:24:45 AM) eileen: yes, it does seem to make sense to default to current domain. but there are cases where you would want to get all - maybe we just allow id=>'all'
(11:24:46 AM) xavier_d1: eileen: make sense (your example)
(11:25:38 AM) totten: I think the first obligation of the API is handling DB CRUD predictably
(11:26:05 AM) totten: for the active/effective value, i'd treat that as a special case -- maybe $action=='resolve'
(11:26:09 AM) xavier_d1: Let's clarify
(11:26:24 AM) totten: whereas $action=='get' means "read the setting record from the DB"
(11:26:24 AM) xavier_d1: (new rules replace previous suggestions)
(11:26:41 AM) JoeMurray: I'm +1 on totten's point about having a way to get the current setting after all policies having been applied (ie for this domain as overridden for this user potentially as maybe overridden by hooks...)
(11:26:45 AM) xavier_d1: get = always return indexed on the domain id (99% a single 1=> record)
(11:26:58 AM) xavier_d1: if no id set
(11:27:44 AM) xavier_d1: create with id=1 sets for the domain
(11:28:31 AM) xavier_d1: (special case: if single domain and no id, set for the domain, if multidomain -> is_error)
(11:28:32 AM) JoeMurray: re: 22k blob - basically that is a caching approach. I like the idea of breaking it up for admin/configuration purposes but assembling rarely for performance. I also like the idea from drupal of breaking this kind of stuff into different pieces that are lazy loaded
(11:29:13 AM) eileen: OK - I'm thinking on totten's suggestion - yes, maybe a getresolved action makes sense - although currently... only for timezone which isn't stored in civi & navigation which still has other stumbilng points - ie. value name is the same for all
(11:29:16 AM) JoeMurray: assemblying == computing

(11:29:22 AM) JoeMurray: pieces == chunks
(11:29:53 AM) eileen: Ok xavier_d1 - I'll write that up & the other stuff up & see if it looks like what you thought you said :-)
(11:29:54 AM) xavier_d1: and for the "kind of doesn't exist special case of resolved" getresolved or get option.resolved=1
(11:30:21 AM) JoeMurray: my agreement and perhaps totten's point was fairly high level re: nice architecture. if there are few cases it's needed then great less work
(11:30:26 AM) eileen: But, still on navigation - you actually have to get ('navigation.contact_id')
(11:31:02 AM) eileen: (I'm still struggling with the fit between navigation & everything else a bit here)
(11:31:17 AM) xavier_d1: let's say that navigation is a separate entity
(11:31:18 AM) JoeMurray: i like the idea of being able to configure navigation by user (staff could benefit from something different). Didn't know CiviCRM had this
(11:31:23 AM) totten: eileen: because navigation is per-contact?
(11:31:37 AM) eileen: totten - yep, so it either has to return logged_in user
(11:31:41 AM) xavier_d1: JoeMurray totten the contact_id is set (that's the only record)
(11:31:52 AM) eileen: or you have to be able to pass in the user
(11:31:57 AM) xavier_d1: but I don't have any db where there is not a single record with contact_id=1
(11:32:13 AM) eileen: JoeMurray - yep, not sure what happens when you do it through the gui in practice

(11:32:55 AM) xavier_d1: anyway as I was saying, navigation is a special case anyway
(11:33:10 AM) xavier_d1: let's say it isn't part of setting but it's a different entity
(11:33:38 AM) eileen: yes, so can just exclude it completely (possibly even from the xml) for now
(11:33:47 AM) xavier_d1: eileen yes
(11:34:07 AM) eileen: Another thought I had though - if we are getting settings from the cms - we could think about specifiying the function in the xml
(11:34:35 AM) JoeMurray: Setting the default nav for a domain is different than overriding it for a particular user
(11:35:16 AM) totten: what do you think of http://pastebin.com/1TxcHYFg ?
(11:35:17 AM) eileen: e.g each userSystem class has a getTimezone (hypothetically) - we could add <xml><tz><function>getTimeZone</function etc & it would call $config->userSystem->getTimeZone()
(11:35:29 AM) JoeMurray: at the moment we can keep this out of scope for the settings api
(11:36:06 AM) eileen: yep JoeMurray - discussing how it might fit doesn't equal planning to do it in the shortterm
(11:36:19 AM) xavier_d1: totten: always id (no domain_id vs contact_id)
(11:36:21 AM) JoeMurray: totten: nice
(11:36:26 AM) dlobo left the room (quit: Client Quit).
(11:37:14 AM) xavier_d1: Setting is only get, no create, right?
(11:37:28 AM) eileen: totten - so that means ContactSetting is in the future, DomainSetting vs Setting is an alternative to the variant X outlined
(11:37:29 AM) JoeMurray: totten: there is a way for contactsetting to override a domainsetting?
(11:37:34 AM) eileen: (or a wrapper for it)
(11:37:43 AM) totten: right
(11:38:15 AM) totten: well, my understanding from talking to dlobo is that was the goal
(11:38:26 AM) totten: (to allow per-contact settings to override per-domain settings)
(11:38:35 AM) JoeMurray: yes, i very much like that
(11:38:38 AM) eileen: but, your version doesn't answer the Q of returning multiple domains does it? Tim?
(11:38:59 AM) JoeMurray: but i defer to others on the number of cases where we have a current or imminent implementation along those lines
(11:39:10 AM) JoeMurray: i think we should build the infrastructure to allow it
(11:39:20 AM) JoeMurray: and then use cases will grow organically
(11:39:27 AM) JoeMurray: since it's such a nice pattern
(11:39:39 AM) eileen: JoeMurray - yes, we (I) should transfer this conversation to the wiki as our long-term-plan
(11:39:52 AM) JoeMurray: actually
(11:39:55 AM) eileen: & I'll do a bit of prototyping
(11:39:59 AM) xavier_d1: eileen: if civicrm_api ('DomainSetting', 'get', return='timezone') would return all the tz for the different domains
(11:40:30 AM) JoeMurray: xavier_d1: I'm thinking that we would very rarely do that call
(11:40:52 AM) JoeMurray: more likely we would want to get the domain's default rather than the current user's override
(11:40:56 AM) xavier_d1: totten: so 'Setting' & 'ContactSetting' will start with very few entities, right?
(11:41:14 AM) eileen: Ah, so, slight change - the default for domainSetting get is to return all domains - whereas setting would return current domains?
(11:41:16 AM) JoeMurray: ContactSetting has very few entities
(11:41:33 AM) JoeMurray: but Setting should work immediately for all might be better
(11:41:44 AM) JoeMurray: then code using that interface
(11:41:54 AM) eileen: Hmm - we've come to different conclusions
(11:41:57 AM) JoeMurray: will allow ContactSettings to be built later
(11:42:10 AM) xavier_d1: JoeMurray, I'm not keen of read on Setting but create on DomainSetting
(11:42:36 AM) eileen: I was thinking that ContactSettings get would return the same as Setting get filtered through the current contact
(11:42:46 AM) eileen: on the current domain
(11:43:05 AM) eileen: DomainSetting get would return settings filtered through the current domain
(11:43:11 AM) JoeMurray: using Setting regularly means one doesn't need to worry if later a ContactSetting gets implemented for that field
(11:43:19 AM) xavier_d1: totten: what's your idea
(11:43:20 AM) JoeMurray: totten: your 2cents?
(11:43:24 AM) eileen: & setting would return all the domains in the DB (only 1 for multisite)
(11:44:01 AM) totten: min. trying to update pastebin
(11:44:24 AM) xavier_d1: ok, no matter what, it means that if the 3 of us read something differently, we're going to have a lot of support on the forums ;)
(11:44:29 AM) majortomlocal left the room (quit: Remote host closed the connection).
(11:45:14 AM) xavier_d1: totten: not sure there will be a D for any of the setting
(11:45:46 AM) pedor left the room (quit: Read error: Connection reset by peer).
(11:46:03 AM) totten: http://pastebin.com/S1cqa936
(11:46:34 AM) totten: tries to communicate the two approaches we've come up with so far
(11:46:55 AM) totten: and incorporate some of the fixes (e.g. "always use 'id'")
(11:48:39 AM) totten: xavier_d1: regarding not liking reading/writing on different entities
(11:48:43 AM) totten: kinda agree and kinda don't
(11:48:56 AM) totten: for someone who's automating site configuration, they'll only work with DomainSetting
(11:49:05 AM) totten: there's no reason for them to read from 'Setting'
(11:49:35 AM) totten: for someone who only wants to consume a setting, they'll only read from 'Setting' -- not from DomainSetting or ContactSetting
(11:50:24 AM) totten: for someone who's doing anything else, life will be confusing -- regardless of our approach
(11:50:37 AM) totten: the best we can do is to minimize confusion
(11:50:37 AM) eileen: totten - do I correctly understand that ContactSetting 'get' will return all the settings -but computed for that user? ie. can I grab any settings via that method & it will be over-ridden if appropriate?
(11:50:59 AM) totten: no, my understanding is that it only returns settings that have been explicitly set for the given user
(11:51:19 AM) totten: defaults, overrides, etc, are only applied for 'Setting'
(11:51:21 AM) eileen: (nb just as an aside - the way we do files & entities it would work better as 'setting','domaincreate' than 'domainsetting','create'
(11:51:31 AM) totten: DomainSetting and ContactSettings are more like dumb entities
(11:51:41 AM) eileen: Oh, I was thinking setting was the straight DB variant
(11:51:45 AM) eileen: I was in reverse
(11:52:20 AM) xavier_d1: I prefer approach A
(11:53:14 AM) xavier_d1: both because it's simplier for the 99% of the use case (single domain) and because it avoids the confusion about which entity is used for what
(11:53:48 AM) eileen: OK - let me take it away & play with it & come back to you guys
(11:54:48 AM) xavier_d1: totten eileen, on the last resolve, any pro/con having a separate action vs. get + options.resolve=1 ?
(11:55:32 AM) eileen: well, what's the default if it's one action?
(11:56:10 AM) totten: i'd lean towards separate because -- in my mind -- the behavior and the semantics are different
(11:56:30 AM) totten: ie "crud'ing a table" vs "cascading policies"
(11:56:38 AM) eileen: (I don't think the default is obvious - which makes me lean to 2 actions)
(11:56:49 AM) xavier_d1: ah, last try
(11:57:16 AM) eileen: but I prefer 'getresolved' over 'resolve' :-)
(11:57:46 AM) xavier_d1: by default setting.create does resolve (of the few returns that make sense, otherwise that's default domain)
(11:58:06 AM) xavier_d1: and if you don't want to resolve but R the domain, you set the id
(11:58:17 AM) eileen: yes, agree on create
(11:59:12 AM) xavier_d1: ie. the get does either what you ask it to do (by setting the id or contact_id), or do the most sensible thing
(11:59:30 AM) xavier_d1: ie resolve when it makes sense, or default to the single domain
(12:00:03 PM) xavier_d1: and is_error if resolve doesn't make sense & multidomain
(12:00:26 PM) eileen: (or return all for multidomain)
(12:00:31 PM) eileen: on get
(12:01:06 PM) xavier_d1: argl, yes
(12:01:38 PM) xavier_d1: so resolve definitely makes sense
(12:02:01 PM) xavier_d1: ok, I'm convinced by Approach A
(12:02:07 PM) totten: fwiw, i'm not sure there is a single "most sensible" thing. there are at least three different cases (from above) -- which means that three different people will make different guesses about what "most sensible" means
(12:02:07 PM) xavier_d1: and that's 2am, nite everyone
(12:02:17 PM) eileen: :-)
(12:02:35 PM) eileen: Yep you head to bed - thanks guys
(12:02:54 PM) xavier_d1 left the room.
(12:02:58 PM) eileen: I think we covered a lot off & I'll take it away & see where I get
(12:03:10 PM) totten: sounds good.
(12:03:21 PM) totten: thanks for moving this along!
(12:03:27 PM) eileen: thank JoeMurray
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Site deployment via the API
May 25, 2012, 04:22:34 am
So, let's see if I got it clear today.

The settings are exposed in the api as fields of a "setting" entity.
there is most of the time a single entity  (id=1), but can have several if multidomain.

Rem: it isn't isn't how the setting are implemented in civicrm_setting, but that how it's abstracted to the api users

For convenience, the create action works without the id parameter is it's a single domain install (and would default to 1 or whatever the id).

The navigation menu is a special case, it will (as in "not part of this batch") be done through a separate entity.

We might have to create a few of "fake" settings, eg to get civicrm version (code or db).

For all the others.

Code: [Select]

civicrm_api('Setting','getfields');
// returns all the settings that are available (currency, language, default_country...)
 
// CRUD for domain-level settings; 'id' means domain_id in all actions

civicrm_api('Setting','get', array(
  'id' => $ // if not set, return the variable for all the domains and a single 1=> for a "normal" mono domain install
  'currency' => $,
));

//REM: for most of the variables, will be the same result for every domain in multidomain

civicrm_api('Setting','create', array(
  'id' => $ // optional if single-domain; mandatory for multiple domain
  'timezone' => $,
));


// CRUD for contact-level settings; 'id' is not used
// REM: right now, there isn't any setting that is per user (at least in civicrm_setting) it seems

civicrm_api('Setting','create', array(
  'contact_id' => $ // optional; default current user
  'timezone' => $,
));

// R for settings
// this one does the magic and retrieve the calculated value, ones priority between the various settings per domain & user & hooks are taken into account
civicrm_api('Setting', 'resolve', array(
  return => 'timezone',
));
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Site deployment via the API

This forum was archived on 2017-11-26.