Monday, May 4, 2020

Yii CActiveRecord Relation to a Relation that is a View

I have tables for Council, Unit, Offices, CouncilOffices, and ViewWithPhonebook. The view is the records for the unit with additional data retrieved from an online phonebook.

CouncilOffices implements a many-to-many relationship between Offices and Council. The council are unit members who hold offices in the organization.

Council Relations

array(
'officeRelation'=>array(self::MANY_MANY, 'Offices', 
                              'council_offices(council_index, offices_index)'
), 
'viewRelation'=>array(self::BELONGS_TO,
            'ViewPhonebook', 'id'),

'unitRelation'=>array(self::BELONGS_TO, 
            'Unit', 'id'),       
);

CouncilOffices Relations

array(
    'councilRelation'=>array(self::BELONGS_TO, 
                             'Council', 'council_index'),
    'officesRelation'=>array(self::BELONGS_TO, 
                             'Offices', 'offices_index'),
);

Offices Relations

array(
     'councilRelation'=>array(self::MANY_MANY, 'Council',
          'council_offices(offices_index, council_index)',
      ),
);

Unit Relations

array(
     'unitRelation'=> array(self::HAS_MANY, 'Council', 'id'),);

ViewWithPhonebook Relations

return array(
     'viewRelation'=> array(self::HAS_MANY, 'Council', 'id'),);

The code worked if I used the unit relation. The problem I had was with the view, since it did not have a primary key. If I tried to include the relation, I received this SQL error.
ON
(`councilRelation`.`id`=`unitRelation`.``) WHERE (year=:year).
It is clear that the generated SQL was looking for a primary key, but couldn't find it. I searched for a long time for a solution. I finally found the solution at http://codeinch.com/yii-set-primary-key-in-model/. Add a primaryKey method to the model and return the name of the primary key.

public function primaryKey() {
    return 'ID';
}

Once this was set, I could retrieve the Council relation from Council Offices and then retrieve the View relation from the Council.

$criteria = new CDbCriteria;
$criteria->condition = 'year=:year';
$criteria->params = array(':year'=>'2020');

$data = CouncilOffices::model()
  ->with(array(
    'councilRelation'
       =>array('select'=>'index, year, id'),        
    'councilRelation.unitRelation'
       =>array('select'=>'ID, Name')))
  ->findAll($criteria);

Sunday, May 3, 2020

Mojave VM in Catalina

I just upgraded to Mac OS Catalina and see that my 32-bit applications are no longer supported.

I have decided to create a Mojave Virtual Machine to be able to run the 32-bit applications.

Ironically, my VirtualBox application was 32-bit! I downloaded a new, 64-bit version.

I followed the steps at https://techsviewer.com/install-macos-10-14-mojave-virtualbox-windows/ to create a Mojave ISO image.

The same site has instructions for creating the virtual machine on Windows, but I want it on Mac. The first few steps can be easily modified for Mojave, 64-bit MacOS. Follow the steps until you are asked to edit the settings after the virtual machine is created. They did not work on Mac. I picked up the steps after the settings were changed and the command line actions were done.

I found a separate site that just had me start the vm after it is created. I was prompted for the ISO I created. The process continued to the recovery screen for OS. I clicked Install OS. The Mojave image was found and then I was able to follow the normal installation for Mojave.

Open VirtualBox and click New.


Proved details for virtual machine (VM), then click Continue.


Specify memory size of 2G.


Specify size of hard drive. Suggested 20GB is too small. Trying 100 GB. Click Create.


Review settings and click Start.


 Select ISO image for mojave and click Start.


Select language and click arrow.


Select Disk Utility from the recovery screen.


Select the VBOX HARDDISK and click Erase in order to format the drive.


Create a volume name, choose Mac OS Extended and GUID partition. The GUID is needed for a bootable disk. Click Create.


Drive is created. Click Done.


Quit Disk Utility from the File menu and select Install macOS from the recovery menu.


The mojave.iso file will be used automatically to install OS. Click Continue.


Accept the license by clicking Agree.


Confirm agreement by clicking Agree.


Select the hard drive created earlier and click Install.


Progress is shown.


After a while, the Apple logo will appear.


Something went wrong.


Shut down machine and restarted. Slow progress at the Apple logo. This is the first Apple logo before the recovery menu appears.



Recreated another VM with same parameters. I made it to recovery menu, erased drive, and started install. Reached the second Apple screen. Freezes with 16 minutes remaining.


I found a page for getting stuck at 16 minutes: https://forums.virtualbox.org/viewtopic.php?f=22&t=94495. One recommendation is to set CPUs to 2 and not 4. I had it set for 4 the first time and 1 the second time. Setting it to 2 let me get to the 6 minute mark.


Still waiting... 2 minutes remaining... less than a minute.


Next came a reboot and sucess!


Finished setup, but the desktop is too small.


I installed the VirtualBox extension pack from https://www.virtualbox.org/wiki/Downloads.

In the preferences for virtual box, I set the display scale to 200%. macOS does not have guest extensions. https://forums.virtualbox.org/viewtopic.php?f=8&t=91128

Next was to set up a shared folder. Guest extensions are not available for macOS. Instead, share a folder from Sharing in System Preferences. I followed these instructions to share a folder: https://techsupport.screenplay.com/hc/en-us/articles/360035782711-Creating-a-Shared-Folder-between-your-Mac-running-Catalina-and-a-Virtual-Machine


I created a folder containing my 32-bit apps and shared it.


The important information is the smb URL. That will be used to connect to shared folder from VM. In the VM, open Finder and select Connect to Server from the Go menu.

Enter the smb url.


Select the volumes to mount.


I have a folder containing the 32-bit software that does not run in Catalina, but runs in the Mojave VM.


Some of my apps were so old that they could not run on Mojave! I will abandon them instead of installing another, older macOS VM.














Saturday, January 18, 2020

Location of resource files in Maven

I am moving a project from NetBeans into Maven in NetBeans.

In the original application, I place resource files in the default package (in classes). In the Maven version, these non-compiled classes are not copied to the Target folder, so they cannot be found at run time.

In Maven, move the files to Other Sources -> src/main/resources.


Thursday, August 22, 2019

Using PHP and PerlBrew

I have phpbrew installed on my mac. I use it to manage my php installation.

The first command I used was

phpbrew known

to view the known PHP versions.

I had not installed any versions, so

phpbrew list

did not show me any.

So, I checked the version - 1.23. GitHub showed a newer version of 1.26. I decided to reinstall phpbrew.

https://github.com/phpbrew/phpbrew

  • used curl to install phpbrew.phar
  • moved to my path
  • made it executable
phpbrew system revealed that my PHP on my Mac under Mojave is outdated, so I installed 7.3 as my system PHP.

After installing, I updated my PATH with 

export PATH=/usr/local/php5/bin:$PATH

I will also add that to my .bashrc

I was trying to install a different PHP version and received errors about missing bzip2 and some other things. I wound up reinstalling Homebrew, because it could not update itself.

Homebrew prefix "/usr/local/Cellar/libxml2/2.9.3" does not exist.

Error: No available formula with the name "bzip2"

Homebrew formula "bzip2" not found.

Homebrew prefix "/usr/local/Cellar/oniguruma/5.9.6" does not exist.

Homebrew prefix "/usr/local/Cellar/mhash/0.9.9.9" does not exist.

Homebrew prefix "/usr/local/Cellar/curl/7.46.0" does not exist.

checking for ZLIB support... no

checking whether to enable bc style precision math functions... yes

checking for BZip2 support... yes

checking for BZip2 in default path... not found

configure: error: Please reinstall the BZip2 distribution

I tried to install some libraries

brew install zlib bzip2 libiconv curl

This is when I tried to update brew and had to reinstall. After brew install, I was able to install the above.

Next, I intalled

phpbrew install 7.4.5 +mysql +default

I still get the error

Homebrew prefix "/usr/local/Cellar/libxml2/2.9.10_1" does not exist.
Homebrew prefix "/usr/local/Cellar/oniguruma/6.9.5" does not exist.
Homebrew prefix "/usr/local/Cellar/mhash/0.9.9.9" does not exist.
Homebrew prefix "/usr/local/Cellar/openssl@1.1/1.1.1g" does not exist.

It looks like I need more stuff for Mac OS:

brew install autoconfig pkg-config

Then

brew upgrade

Could not find autoconfig formula.

Still can't install PHP. It did find the openssl folder.

brew install libxml2 onigurma mhash

Installed missing packages with brew.

Still can't install PHP versions.

Inspect

tail /Users/timdowney/.phpbrew/build/php-7.4.5/build.log

Missing link to pkg-config, tried

brew link pkg-config

Missing libzip

brew install libzip

Tried to install 7.4.5 again.

Congratulations! Now you have PHP with 7.4.5 as php-7.4.5

* We found that you enabled 'mysql' variant, you might need to setup your
  'pdo_mysql.default_socket' or 'mysqli.default_socket' in your php.ini file.

* To configure your installed PHP further, you can edit the config file at
    /Users/timdowney/.phpbrew/php/php-7.4.5/etc/php.ini

To use the newly built PHP, try the line(s) below:

    $ phpbrew use php-7.4.5

Or you can use switch command to switch your default php to php-7.4.5:

    $ phpbrew switch php-7.4.5












Friday, July 12, 2019

Creating Maven from non-Maven project in NetBeans.

I have a project in NetBeans that is difficult to commit to a version control system (VCS), since the libraries are not saved to the VCS. For several reasons, it is a bad idea to try to save the libraries to the VCS: they are binaries, many duplicates of the files could be saved to the VCS.

An alternative is to use Maven. The POM file in Maven references all the necessary libraries. When the project is downloaded from the VCS, opened, and run, the POM will guarantee that all necessary libraries are downloaded from the cloud.

I have created a new Maven project and am copying the files from the original project into the new Maven project. I will list the libraries that are missing as I copy.

Libraries:

  • org.apache,commons.beanutils - 1.9.3 [jar] local
  • org.apache.log4j - 1.2.15 [jar]
  • org.hibernate.validator.engine - 6.0.10.Final [jar]
  • org.hibernate - 5.2.17
  • org.springframework.beans - 5.0.8 RELEASE [jar] local
  • org.springframework.web - 5.0.8 RELEASE [jar] local
  • org.springframework.context - 5.0.8 RELEASE [jar] local
  • org.springframework.transaction - 5.0.8 RELEASE [jar] local
  • org.springframework.web.servlet - 5.0.8 RELEASE [jar] local 
  • org.springframework.jdbc - 5.0.8 RELEASE [jar] local 
  • org.springframework.orm - 4.2.5 RELEASE [jar] local 
Missing Libraries:
  • com.paypal.sdk.core .exceptions . profiles .services
  • com.fedex.ws.rate
  • org.apache.fop
  • org.apache.xmlgraphics
  • org.w3c.tidy
  • org.apache.avalon
In order to make the project portable, I must place the missing libraries into a remote Maven repo.
  • fop.jar
  • avalon-framework-4.2.0.jar
  • jtidy-r938.jar 
  • mailapi.jar
  • paypal_base.jar
  • paypal_juint.jar
  • RateService.jar
  • xmlgraphics-commons-1.4.jar
For now, I will place these into a folder on the website, until I figure out how to create a Maven repo.

Harder than I thought. To install into the local .m2/repository, run the maven install command  for each library:

    mvn install:install-file -Dfile=/Users/me/Downloads/jar-missing/jtidy-r938.jar
        -DgroupId=org.w3c.tidy -DartifactId=jtidy -Dversion=r938 -Dpackaging=jar

I edited the pom file for each library:

       
            org.w3c.tidy
            jtidy
            r938
            jar
       


I still needed more dependencies. These are used in log4j 1.2.15, but not in log4j 1.2.16. I upgraded to 1.2.16.

javax.jms:jms:jar:1.1
com.sun.jdmk:jmxtools:jar:1.2.1
com.sun.jmx:jmxri:jar:1.2.1

Two new dependencies were needed:

        <!-- https://mvnrepository.com/artifact/com.sun.xml/jaxws-rt -->
        <dependency>
            <groupid>com.sun.xml</groupid>
            <artifactid>jaxws-rt</artifactid>
            <version>2.0EA3</version>
        </dependency>
        <dependency>
            <groupid>javax.jws</groupid>
            <artifactid>jsr181-api</artifactid>
            <version>1.0-MR1</version>
        </dependency><br />

... and mysql:


        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupid>mysql</groupid>
            <artifactid>mysql-connector-java</artifactid>
            <version>8.0.16</version>
        </dependency>


I still needed jstl and standard for taglibs.

I will explore creating a remote repo.





Friday, May 18, 2018

Audible on Garmin Nuvi

I have a Garmin Nuvi 650. It is old. I cannot find the Audible Manager for Mac that allows me to add books to the GPS.

I used to be able to add books to it.

I changed the SD card, so the old file structure was gone.

I downloaded the book files to my computer.

The fix was simple. Add a folder named Audible in the root of the SD card and copy the book files using Finder. I can listen to the books now.

Nuvi only recognizes .aa format, not .aax. Before downloading from Audible, select the Format4 option, which will download as .aa files.

Thursday, May 17, 2018

Sanitize RV Water System

I have adapted the notes form https://www.rvtrader.com/research/news-reviews/press-room/rv-how-tips-sanitize-your-rv-water-system.


  1. Drain the water heater.
  2. Open drain plug and all faucets.
  3. Turn off water pump when empty.
  4. The recommended ratio of bleach to water is 1/4 cup per 15 gallons. I have a 24 gallon tank, with a 6 gallon hot water heater. I will add 1/2 cup to 30 gallons.
  5. Add the bleach to a gallon of water and added it to the water tank.
  6. Fill the water tank with potable water.
  7. Run the faucets until bleach is smelled from each.
  8. Close valves.
  9. Drive truck to agitate the mixture.
  10. Let sit for 12 hours.
  11. Drain, including hot water heater.
  12. Fill with water. Run faucets until bleach smell is gone.
  13. Drain and fill.

More Blogs

Followers