I am new into Zend Framework 3 programming.
Previously we create a project having all database table's mapping included in one particulare module.
Now, we need to create another module into the same project. So we would like to put outside from the first module the database mapping objects in order to shared tha classes between the both modules.
I try to create a new module only for the mapping, but without succes. The namespaces doesn't existes.
After I look for solution like using ServiceManager, but I didn't really understand how to used it.
Do you know if there is another solution than using a ServiceManager ? And if not, have I change all my previous code using objects included simply with the key word use, in order to use the ServiceManager ?
Thanks.
Finaly in my solution I create a module containing only the sources files for the doctrine mapping under src directory.
/module
/MyApplication
/src
/config
/module.config.php
/Common
/src
/DoctrinMapping
/Entities
composer.json
In composer.json I put :
"autoload": {
"psr-4": {
"MyApplication\\": "module/MyApplication/src/"
,"Common\\":"module/Common/src/"
}
}
At the project root I execute the commande line :
composer dump-autoload
After into module.config.php of the my specifique application I define the doctrine reference as :
,'doctrine' =>
[
'driver' =>
[
'common_entities' =>
[
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver'
,'cache' => 'array'
,'paths' => array(__DIR__ . '/../../Common/src/DoctrineMapping/Entities')
],
'orm_default' =>
[
'drivers' =>
[
'Common\DoctrineMapping\Entities' => 'common_entities'
]
]
]
]
That works, but I don't know if this is the best solution to apply.
I had a ruby Sinatra app and gem pg to use some Java open source applications, I switched to jruby. This is the output for jruby -S rake db:migrate.
NoMethodError: undefined method `get_oid_type' for #<ActiveRecord::ConnectionAdapters::JdbcAdapter:0x294f9d50>
api/tasks/db.rake:18:in `block in (root)'
rake file
require 'active_record'
require 'jdbc/postgresql'
namespace :db do
task(:environment) do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'org.postgresql.Driver',
:url => 'jdbc:postgresql:db_name',
:username => 'username',
:password => 'password'
)
end
desc 'Migrate the MOT core models (options: VERSION=x, VERBOSE=false)'
task :migrate => :environment do
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate "#{File.dirname(__FILE__)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : nil
end
desc 'Rolls the schema back to the previous version of MOT core model(specify steps w/ STEP=n).'
task :rollback => :environment do
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
ActiveRecord::Migrator.rollback "#{File.dirname(__FILE__)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : step
end
end
db.rake:#18
ActiveRecord::Migrator.migrate "#{File.dirname(FILE)}/../db/migrate", ENV['VERSION'] ? ENV['VERSION'].to_i : nil
I am running postgresql with jdbc.
UPDATE
I add the postgresql.jar to my jruby path (jruby installed by brew in my mac) and I am getting the same error. I also removed the jar file and I had driver not found error.
Thanks for your help.
simply use adapter: postgresql in your configuration and it should work just fine.
I found the solution.
First make sure you have the followings in your Gemfile
gem 'activerecord-jdbc-adapter', :require => 'arjdbc'
gem 'activerecord-jdbcpostgresql-adapter'
then in your db migrate task this is the setup for environment:
task(:environment) do
ActiveRecord::Base.establish_connection(
:adapter => 'jdbcpostgresql',
:driver => 'org.postgresql.Driver',
:url => 'jdbc:postgresql://localhost/YOUR_DATABASE_NAME'
)
end
Also this is the database.yaml for development:
development:
adapter: jdbcpostgresql
driver: org.postgresql.Driver
encoding: unicode
url: jdbc:postgresql://localhost/YOUR_DATABASE_NAME
username: USER_NAME
password: PASSWORD
Enjoy your JDBC with Jruby on Sinatra application !!!!
While running the command
puppet apply --verbose --debug --modulepath puppet/manifests/modules
puppet/manifests/devbox.pp
I get the following error
err:/Stage[main]/Mongo-datastore/Package[mongodb]/ensure: change from absent to present failed:Could not find package mongo-10genmongo-10gen-server
To fix this error I installed mongodb manually and i changed the mongodb entry in the following package as
name => ["mongodb-org-2.6.4.1""mongodb-org-2.6.4.1"]**
package {
"mongodb":
name => ["mongo-10gen", "mongo-10gen-server"],
ensure => installed,
require => File['/etc/yum.repos.d/10gen.repo'];
}
Can you please tell me why I need to manually install the package while I have already written the script to install mongo-10gen and mongo-10gen-server.
I have a problem for including Zend Framework in Symfony 2 IN PRODUCTION, because when i use it on local there is no problem ...
I just commited my work on my production server and i have this error :
Fatal error: Class 'Zend_Gdata_AuthSub' not found
And there is this error for any classes of Zend Framework ...
This is my autoload which is good for localhost :
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
$loader->add('Zend_', __DIR__.'/../vendor/zf/library');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
set_include_path(__DIR__.'/../vendor/zf/library'.PATH_SEPARATOR.get_include_path());
return $loader;
?>
There is probably a problem with the include path but i don't know why ...
Thanks a lot !
If you want to use Composer to pull in the components you need from ZF2 then you could use the information at Zend Framework site Composer info page
As an example you can add code like this to your composer.json file to enable the repository:
"repositories": [
{
"type": "composer",
"url": "https://packages.zendframework.com/"
}
],
"require": {
"zendframework/zend-config": "2.0.*",
"zendframework/zend-http": "2.0.*"
},
You place the names of the packages you want to pull in under the "require" section and the list of available packages is at the link I supplied so you can check the names there.
When you go to install the dependencies you can use this command:
php composer.phar install
Does that help? :-)
Is there a way to obtain version info for a moodle site using only "teacher" level access? It seems as though this ability was removed in versions 1.9.7 and above. I'm trying to automate the process of uploading tests and having the version info would be rather handy.
In order to see the current version of moodle you just need to read this file:
http://yourmoodlesite/lib/upgrade.txt
Here's more information about it:
https://github.com/moodle/moodle/blob/MOODLE_29_STABLE/lib/upgrade.txt
Sorry, these instructions may seem somewhat obscure, but it's the only way I could find to get the version of Moodle with only "teacher" level access.
As a teacher, you should be able to create a backup of any of your courses (though this capability may have been removed in the Moodle you're using). Backups are just zip files, but instead have a .mbz extension. If you change this extension to .zip, you'll be able to extract the zip. With the zip extracted, open "moodle_backup.xml", in there you should find the "moodle_release" item somewhere near the top, giving you the version of Moodle used to create the backup.
Being a TA, I didn't want to mess around with backups which sounds weird but given my unique position, reasonable (to me).
On the implementation of moodle I use, with TA privilege, a link to moodle docs is present at the bottom of the page and if you open this link, it takes you to the moodle docs page with moodle_url/moodle_version/___.
Maybe this is peculiar to my system, but I believe it's a default setting thing.
The most dirty way to do so when no admin or file access, is doing differs from public files between versions. As example, index.php file can be 1024Kb lenght on v1.x and 1033Kb lenght on version 1.2.
Also, check for existance/non existance of a set of files is a common way (css, html, js, icon, etc)
I will edit this again if i find a specific solution.
First edit:
For versions 19 or above, you can check version direcly from readme.txt file at https://github.com/moodle/moodle/blob/MOODLE_19_STABLE/README.txt
If you don't even have an account on the instance, you may still be able to find out the version. Any authentication errors in the API will return an error message of the form:
[{
"error":true,
"exception":{
"message":"Course or activity not accessible.",
"errorcode":"requireloginerror",
"link":"https:\/\/moodle.example.com\/",
"moreinfourl":"http:\/\/docs.moodle.org\/36\/en\/error\/moodle\/requireloginerror"
}
}]
And the moreinfourl contains an approximate version number (in this case 3.6). For me, this page was requested when I visited the login page for the instance - a POST request to
https://moodle.example.com/lib/ajax/service.php?sesskey=JQrdIcgMn4&info=core_fetch_notifications
My helper function here:
https://gist.github.com/tigusigalpa/af051a9112512b1b0369572b5dbea2fd
function checkMoodleVersion($version, $checkfor = 'all', $compare = '<=') {
global $CFG;
$versions = [
'3.1' => [
'version' => '2016052300',
'release' => '3.1'
],
'3.2' => [
'version' => '2016120500',
'release' => '3.2'
],
'3.3' => [
'version' => '2017051500',
'release' => '3.3'
],
'3.4' => [
'version' => '2017111300',
'release' => '3.4'
],
'3.5' => [
'version' => '2018051700',
'release' => '3.5'
],
'3.6' => [
'version' => '2018120300',
'release' => '3.6'
]
];
switch ($checkfor) {
case 'all':
if (isset($versions[$version]['version'])) {
return version_compare($versions[$version]['version'], $CFG->version, $compare) &&
version_compare($version, $CFG->release, $compare);
}
break;
case 'version':
case 'release':
if (isset($versions[$version][$checkfor])) {
return version_compare($versions[$version][$checkfor], $CFG->$checkfor, $compare);
}
break;
}
return false;
}
Not by default as this could be used to harvest out of date moodle sites.
You could create a script to do this fairly easily, eg:
<?php
require_once('config.php');
echo 'Version: '.$CFG->version;
echo 'Humand readable release: '.$CFG->release;